diff --git a/explorer/src/main.rs b/explorer/src/main.rs index 5b8a17d..954007e 100644 --- a/explorer/src/main.rs +++ b/explorer/src/main.rs @@ -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 { state.builder.place_piece(piece); state.position = state.builder.build(); } + Some(("sight", matches)) => { + let square = matches + .get_one::("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::("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);