[explorer] Add zobrist command

It prints the hash of the board!
This commit is contained in:
Eryn Wells 2025-06-07 08:09:36 -07:00
parent d44c5d6a11
commit fb8a8d6110

View file

@ -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<CommandResult> {
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}"))?;