diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-01-25 03:12:20 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-01-25 03:12:20 +0300 |
commit | 46b862a25203cb492dd45ba1696a28338a42065b (patch) | |
tree | 3a68d3e5e99e514a303a2842653cbbfa3dc5bf3b /src/board/engine.rs | |
parent | 05e6d002225f561c9725b25ef7960bc10421f723 (diff) | |
download | chessnost-46b862a25203cb492dd45ba1696a28338a42065b.tar.gz |
feat: incrementally update zobrist hash
Diffstat (limited to 'src/board/engine.rs')
-rw-r--r-- | src/board/engine.rs | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs index d00b89b..73c57af 100644 --- a/src/board/engine.rs +++ b/src/board/engine.rs @@ -29,6 +29,7 @@ impl Board { for mov in moves { let ep_target_before = self.ep_target.clone(); let castling_rights_before = self.castling_rights.clone(); + let hash_before = self.hash.clone(); let captured_piece = self.make_move(mov); // King can not be in check after our own move if !self.is_king_in_check(color) { @@ -64,7 +65,7 @@ impl Board { result.en_passants += subtree_result.en_passants; } - self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before); + self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); } if print { @@ -126,12 +127,13 @@ impl Board { for mov in moves { let ep_target_before = self.ep_target.clone(); let castling_rights_before = self.castling_rights.clone(); + let hash_before = self.hash.clone(); let captured_piece = self.make_move(mov); if !self.is_king_in_check(color) { let (mut evaluation, mut subtree_pv) = self.negamax_search(-beta, -alpha, depth_left - 1); evaluation *= -1.; - self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before); + self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); if evaluation >= beta { return (beta, principal_variation); // Fail-hard beta-cutoff @@ -143,7 +145,7 @@ impl Board { principal_variation.append(&mut subtree_pv); } } else { - self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before); + self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); } } (alpha, principal_variation) @@ -167,11 +169,12 @@ impl Board { for mov in tactical_moves { let ep_target_before = self.ep_target.clone(); let castling_rights_before = self.castling_rights.clone(); + let hash_before = self.hash.clone(); let captured_piece = self.make_move(*mov); if !self.is_king_in_check(color) { let evaluation = -self.quiscence(-beta, -alpha); - self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before); + self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before, hash_before); if evaluation >= beta { return beta; // Fail-hard beta-cutoff @@ -180,7 +183,7 @@ impl Board { alpha = evaluation; } } else { - self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before); + self.unmake_move(*mov, captured_piece, ep_target_before, castling_rights_before, hash_before); } } |