diff options
| author | Mike White <botahamec@outlook.com> | 2021-09-18 23:21:32 -0400 |
|---|---|---|
| committer | Mike White <botahamec@outlook.com> | 2021-09-18 23:21:32 -0400 |
| commit | 20b6a686b8b67b2d9ceda4875c179c0e693689af (patch) | |
| tree | b84ac8ce8b459d869273a038bed4e5565c1e18ae /ai/src/lib.rs | |
| parent | 8c5fd29965535380516b15792bc23e540f1b6510 (diff) | |
Fixed the best move so it would actually make good moves
Diffstat (limited to 'ai/src/lib.rs')
| -rw-r--r-- | ai/src/lib.rs | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/ai/src/lib.rs b/ai/src/lib.rs index 426ee47..21fcf1e 100644 --- a/ai/src/lib.rs +++ b/ai/src/lib.rs @@ -142,9 +142,11 @@ pub fn best_move(depth: usize, board: CheckersBitBoard) -> Move { let mut best_eval = 0.0; let mut best_move = MaybeUninit::uninit(); for current_move in PossibleMoves::moves(board) { - let current_eval = eval_multithreaded(depth - 1, best_eval, 1.0, unsafe { - current_move.apply_to(board) - }); + let new_board = unsafe { current_move.apply_to(board) }; + let mut current_eval = eval_multithreaded(depth - 1, best_eval, 1.0, new_board); + if new_board.turn() != board.turn() { + current_eval = 1.0 - current_eval; + } if current_eval > best_eval { best_eval = current_eval; best_move = MaybeUninit::new(current_move); |
