diff options
author | eug-vs <eugene@eug-vs.xyz> | 2023-09-04 14:41:07 +0300 |
---|---|---|
committer | eug-vs <eugene@eug-vs.xyz> | 2023-09-04 14:41:07 +0300 |
commit | daabb55e5f4a78e826ed94f90800ff71824fd1e9 (patch) | |
tree | 1b41cec6f8d76bbe45699d084d02bd6e0c8cec63 /src/grossmeister | |
parent | 9d8304d35d5f9e8f9e70f231971b064e9e22ad68 (diff) | |
download | chessnost-daabb55e5f4a78e826ed94f90800ff71824fd1e9.tar.gz |
perf: add ttable to quiescence
Huge performance boost!
Diffstat (limited to 'src/grossmeister')
-rw-r--r-- | src/grossmeister/search.rs | 55 |
1 files changed, 48 insertions, 7 deletions
diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index 15cae3a..f56d97d 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -171,6 +171,24 @@ impl Grossmeister { return 0.0 } + if let Some(transposition) = self.transposition() { + match transposition.node_type { + NodeType::PV | NodeType::Cut => { + if transposition.score >= beta { + return beta + } + if transposition.score > alpha { + alpha = transposition.score + } + } + NodeType::All => { + if transposition.score <= alpha { + return alpha + } + } + } + } + // Mate distance pruning let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); if mating_score != 0.0 { @@ -208,10 +226,33 @@ impl Grossmeister { self.board.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); if evaluation >= beta { + self.store_transposition(TranspositionTableItem { + hash: self.board.hash, + mov: Some(mov), + depth: 0, + node_type: NodeType::Cut, + score: beta, + }); + return beta; // Fail-hard beta-cutoff } if evaluation > alpha { + self.store_transposition(TranspositionTableItem { + hash: self.board.hash, + mov: Some(mov), + depth: 0, + node_type: NodeType::PV, + score: evaluation, + }); alpha = evaluation; + } else { + self.store_transposition(TranspositionTableItem { + hash: self.board.hash, + mov: None, + depth: 0, + node_type: NodeType::All, + score: alpha, + }); } } else { self.board.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); @@ -225,8 +266,8 @@ impl Grossmeister { alpha } - fn reconstruct_pv(&mut self, depth: u8) -> Vec<Move> { - let mut pv = Vec::with_capacity(depth as usize); + fn reconstruct_pv(&mut self) -> Vec<Move> { + let mut pv = Vec::new(); if let Some(transposition) = self.transposition() { if let Some(mov) = transposition.mov { @@ -235,14 +276,14 @@ impl Grossmeister { let hash_before = self.board.hash; let captured = self.board.make_move(mov); - let mut subtree_pv = self.reconstruct_pv(depth - 1); - self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before); - pv.push(mov); + let mut subtree_pv = self.reconstruct_pv(); pv.append(&mut subtree_pv); + + self.board.unmake_move(mov, captured, ep_target_before, castling_rights_before, hash_before); + } } - debug_assert!(pv.len() == depth as usize); pv } @@ -289,7 +330,7 @@ impl Grossmeister { } best_score = score; - pv = self.reconstruct_pv(depth); + pv = self.reconstruct_pv(); // Print UCI info print!("info depth {} score ", depth); |