diff --git a/explorer/src/main.rs b/explorer/src/main.rs index 59b790d..9da0ae6 100644 --- a/explorer/src/main.rs +++ b/explorer/src/main.rs @@ -90,6 +90,7 @@ fn command_line() -> Command { ) .subcommand(Command::new("print").about("Print the board")) .subcommand(Command::new("quit").alias("exit").about("Quit the program")) + .subcommand(Command::new("zobrist").about("Print the Zobrist hash of the current board")) } #[derive(Clone, Debug, Error, Eq, PartialEq)] @@ -175,6 +176,7 @@ fn respond(line: &str, state: &mut State) -> anyhow::Result { Some(("moves", matches)) => result = do_moves_command(state, matches)?, Some(("movement", matches)) => result = do_movement_command(state, matches)?, Some(("reset", matches)) => result = do_reset_command(state, matches)?, + Some(("zobrist", matches)) => result = do_zobrist_command(state, matches), Some((name, _matches)) => unimplemented!("{name}"), None => unreachable!("Subcommand required"), } @@ -269,6 +271,19 @@ fn do_movement_command( }) } +fn do_zobrist_command(state: &mut State, _matches: &clap::ArgMatches) -> CommandResult { + if let Some(hash) = state.position.zobrist_hash() { + println!("hash:{hash}"); + } else { + println!("No Zobrist hash available"); + } + + CommandResult { + should_continue: true, + should_print_position: false, + } +} + fn main() -> Result<(), String> { let mut editor = DefaultEditor::new().map_err(|err| format!("Error: {err}"))?;