[expolorer] Add two new commands for showing available moves and sight of a piece on a square
This commit is contained in:
parent
a78526befa
commit
539b1fca6e
1 changed files with 38 additions and 0 deletions
|
@ -54,6 +54,16 @@ fn command_line() -> Command {
|
|||
.arg(Arg::new("square").required(true))
|
||||
.about("Place a piece on the board"),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("sight")
|
||||
.arg(Arg::new("square").required(true))
|
||||
.about("Show sight of a piece on a square"),
|
||||
)
|
||||
.subcommand(
|
||||
Command::new("moves")
|
||||
.arg(Arg::new("square").required(true))
|
||||
.about("Show moves of a piece on a square"),
|
||||
)
|
||||
.subcommand(Command::new("print").about("Print the board"))
|
||||
.subcommand(Command::new("quit").alias("exit").about("Quit the program"))
|
||||
.subcommand(Command::new("starting").about("Reset the board to the starting position"))
|
||||
|
@ -134,6 +144,34 @@ fn respond(line: &str, state: &mut State) -> Result<CommandResult, String> {
|
|||
state.builder.place_piece(piece);
|
||||
state.position = state.builder.build();
|
||||
}
|
||||
Some(("sight", matches)) => {
|
||||
let square = matches
|
||||
.get_one::<String>("square")
|
||||
.ok_or("Missing square")?;
|
||||
let square = Square::from_algebraic_str(square)
|
||||
.map_err(|_| "Error: invalid square specifier")?;
|
||||
|
||||
let sight = state.position.sight(square);
|
||||
|
||||
let display = state.position.display().highlight(sight);
|
||||
println!("\n{display}");
|
||||
|
||||
result.should_print_position = false;
|
||||
}
|
||||
Some(("moves", matches)) => {
|
||||
let square = matches
|
||||
.get_one::<String>("square")
|
||||
.ok_or("Missing square")?;
|
||||
let square = Square::from_algebraic_str(square)
|
||||
.map_err(|_| "Error: invalid square specifier")?;
|
||||
|
||||
let movement = state.position.movement(square);
|
||||
|
||||
let display = state.position.display().highlight(movement);
|
||||
println!("\n{display}");
|
||||
|
||||
result.should_print_position = false;
|
||||
}
|
||||
Some(("starting", _matches)) => {
|
||||
let starting_position = Position::starting();
|
||||
state.builder = PositionBuilder::from_position(&starting_position);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue