From 01b456b4fef8ce4a002f870e5385424614a2a5fb Mon Sep 17 00:00:00 2001 From: Mike White Date: Wed, 15 Sep 2021 20:49:13 -0400 Subject: Added best move function --- cli/src/eval.rs | 6 +++++- cli/src/main.rs | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) (limited to 'cli') diff --git a/cli/src/eval.rs b/cli/src/eval.rs index d078c5f..72fa32a 100644 --- a/cli/src/eval.rs +++ b/cli/src/eval.rs @@ -1,4 +1,8 @@ -use ai::CheckersBitBoard; +use ai::{CheckersBitBoard, Move}; pub fn eval(depth: usize) -> f32 { ai::eval(depth, 0.0, 1.0, CheckersBitBoard::starting_position()) } + +pub fn best_move(depth: usize) -> Move { + ai::best_move(depth, CheckersBitBoard::starting_position()) +} diff --git a/cli/src/main.rs b/cli/src/main.rs index a550092..d230398 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -31,6 +31,17 @@ fn main() { .help("The depth to go to"), ), ) + .subcommand( + SubCommand::with_name("best") + .about("Calculate the best move") + .arg( + Arg::with_name("depth") + .required(true) + .short("d") + .takes_value(true) + .help("The depth to go to"), + ), + ) .get_matches(); if let Some(matches) = matches.subcommand_matches("perft") { @@ -59,4 +70,17 @@ fn main() { ) ); } + + if let Some(matches) = matches.subcommand_matches("best") { + println!( + "{}", + eval::best_move( + matches + .value_of("depth") + .unwrap() + .parse() + .expect("Error: not a valid number") + ) + ) + } } -- cgit v1.2.3