diff options
| author | Mike White <botahamec@outlook.com> | 2021-09-05 22:14:17 -0400 |
|---|---|---|
| committer | Mike White <botahamec@outlook.com> | 2021-09-05 22:14:17 -0400 |
| commit | 3df9c8a9a2f9274e863785fc9a7b196fe20ee87d (patch) | |
| tree | 22a0c7291425f5af9f087335b25042c19a6844b1 | |
| parent | 411d1849cdbce169aefb7b031e7808ebedaabcc9 (diff) | |
Fixed evaluation and created eval command
| -rw-r--r-- | ai/src/lib.rs | 4 | ||||
| -rw-r--r-- | cli/src/eval.rs | 4 | ||||
| -rw-r--r-- | cli/src/main.rs | 16 |
3 files changed, 22 insertions, 2 deletions
diff --git a/ai/src/lib.rs b/ai/src/lib.rs index cdd8f2e..583c50b 100644 --- a/ai/src/lib.rs +++ b/ai/src/lib.rs @@ -26,7 +26,7 @@ fn eval_position(board: CheckersBitBoard) -> f32 { } } -fn eval(depth: usize, board: CheckersBitBoard) -> f32 { +pub fn eval(depth: usize, board: CheckersBitBoard) -> f32 { if depth == 0 { eval_position(board) } else { @@ -35,7 +35,7 @@ fn eval(depth: usize, board: CheckersBitBoard) -> f32 { for current_move in PossibleMoves::moves(board) { let board = unsafe { current_move.apply_to(board) }; let current_eval = if board.turn() != turn { - -eval(depth - 1, board) + 1.0 - eval(depth - 1, board) } else { eval(depth - 1, board) }; diff --git a/cli/src/eval.rs b/cli/src/eval.rs new file mode 100644 index 0000000..eaa2d41 --- /dev/null +++ b/cli/src/eval.rs @@ -0,0 +1,4 @@ +use ai::CheckersBitBoard; +pub fn eval() -> f32 { + ai::eval(12, CheckersBitBoard::starting_position()) +} diff --git a/cli/src/main.rs b/cli/src/main.rs index f7fcddf..57991f0 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -1,6 +1,7 @@ use ai::CheckersBitBoard; use clap::{App, Arg, SubCommand}; +mod eval; mod perft; fn main() { @@ -19,6 +20,17 @@ fn main() { .help("The depth to go to"), ), ) + .subcommand( + SubCommand::with_name("eval") + .about("Calculate the advantage") + .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") { @@ -34,4 +46,8 @@ fn main() { ) ); } + + if let Some(_matches) = matches.subcommand_matches("eval") { + println!("{}", eval::eval()); + } } |
