diff options
| -rw-r--r-- | ai/src/lib.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ai/src/lib.rs b/ai/src/lib.rs index 4e22708..c5b60f0 100644 --- a/ai/src/lib.rs +++ b/ai/src/lib.rs @@ -1,3 +1,5 @@ +use std::f32::NEG_INFINITY; + pub use model::{CheckersBitBoard, Move, PieceColor, PossibleMoves}; const KING_WORTH: u32 = 2; @@ -25,3 +27,26 @@ fn eval_position(board: CheckersBitBoard) -> f32 { 0.0 } } + +fn eval(depth: usize, board: CheckersBitBoard) -> f32 { + if depth == 0 { + eval_position(board) + } else { + let turn = board.turn(); + let mut best_eval = -NEG_INFINITY; + 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) + } else { + eval(depth - 1, board) + }; + + if best_eval < current_eval { + best_eval = current_eval; + } + } + + best_eval + } +}
\ No newline at end of file |
