[explorer] make command no longer requires specifying a piece
This commit is contained in:
parent
6e0e33b5f9
commit
00c4aa38f0
1 changed files with 6 additions and 13 deletions
|
@ -42,7 +42,6 @@ fn command_line() -> Command {
|
||||||
.subcommand(Command::new("fen").about("Print the current position as a FEN string"))
|
.subcommand(Command::new("fen").about("Print the current position as a FEN string"))
|
||||||
.subcommand(
|
.subcommand(
|
||||||
Command::new("make")
|
Command::new("make")
|
||||||
.arg(Arg::new("piece").required(true))
|
|
||||||
.arg(Arg::new("from").required(true))
|
.arg(Arg::new("from").required(true))
|
||||||
.arg(Arg::new("to").required(true))
|
.arg(Arg::new("to").required(true))
|
||||||
.about("Make a move"),
|
.about("Make a move"),
|
||||||
|
@ -95,11 +94,6 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
result.should_print_position = false;
|
result.should_print_position = false;
|
||||||
}
|
}
|
||||||
Some(("make", matches)) => {
|
Some(("make", matches)) => {
|
||||||
let shape = matches
|
|
||||||
.get_one::<String>("piece")
|
|
||||||
.ok_or("Missing piece descriptor")?;
|
|
||||||
let shape = Shape::try_from(shape).map_err(|_| "Invalid piece descriptor")?;
|
|
||||||
|
|
||||||
let from_square = Square::from_algebraic_str(
|
let from_square = Square::from_algebraic_str(
|
||||||
matches.get_one::<String>("from").ok_or("Missing square")?,
|
matches.get_one::<String>("from").ok_or("Missing square")?,
|
||||||
)
|
)
|
||||||
|
@ -110,17 +104,16 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
||||||
)
|
)
|
||||||
.map_err(|_| "Error: invalid square specifier")?;
|
.map_err(|_| "Error: invalid square specifier")?;
|
||||||
|
|
||||||
let mv = MoveBuilder::new()
|
let ply = MoveBuilder::new()
|
||||||
.from(from_square)
|
.from(from_square)
|
||||||
.to(to_square)
|
.to(to_square)
|
||||||
.build()
|
.build()
|
||||||
.map_err(|err| format!("Error: cannot build move: {:?}", err))?;
|
.map_err(|err| format!("Error: {err:?}"))?;
|
||||||
|
|
||||||
state.position = MakeMoveBuilder::new(&state.position)
|
state
|
||||||
.make(&mv)
|
.position
|
||||||
.map_err(|err| format!("Error: cannot make move: {:?}", err))?
|
.make_move(ply, ValidateMove::Yes)
|
||||||
.build();
|
.map_err(|err| format!("Error: {err}"))?;
|
||||||
state.builder = PositionBuilder::from_position(&state.position);
|
|
||||||
}
|
}
|
||||||
Some(("place", matches)) => {
|
Some(("place", matches)) => {
|
||||||
let color = matches
|
let color = matches
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue