From 19c2df8907ebc0d13c4d745796ce63a34083186a Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 19 Jan 2024 17:21:35 +0100 Subject: feat!: try again with ttable in quiescence But now with exact scores in table --- src/grossmeister/search.rs | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'src/grossmeister') diff --git a/src/grossmeister/search.rs b/src/grossmeister/search.rs index 0df0628..bf080eb 100644 --- a/src/grossmeister/search.rs +++ b/src/grossmeister/search.rs @@ -172,10 +172,38 @@ impl Grossmeister { return 0.0 } + if let Some(transposition) = self.transposition() { + match transposition.node_type { + NodeType::PV => { + return transposition.score.clamp(alpha, beta); + } + NodeType::Cut => { + if transposition.score >= beta { + return beta; + } + alpha = transposition.score.clamp(alpha, beta); + } + NodeType::All => { + if transposition.score <= alpha { + return alpha; + } + beta = transposition.score.clamp(alpha, beta); + } + } + } + + let mut transposition = TranspositionTableItem { + hash: self.board.hash, + depth: 0, + mov: None, + score: alpha, + node_type: NodeType::All, + }; // Mate distance pruning let mating_score = Grossmeister::MDP(&mut alpha, &mut beta, root_distance); if mating_score != 0.0 { + transposition.score = mating_score; return mating_score } @@ -210,10 +238,22 @@ impl Grossmeister { self.board.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); if evaluation >= beta { + transposition.mov = Some(mov); + transposition.score = evaluation; + transposition.node_type = NodeType::Cut; + self.store_transposition(transposition); + return beta; // Fail-hard beta-cutoff } if evaluation > alpha { + transposition.mov = Some(mov); + transposition.score = evaluation; + transposition.node_type = NodeType::Cut; alpha = evaluation; + } else if transposition.node_type == NodeType::All { + transposition.mov = None; + transposition.score = evaluation; + transposition.node_type = NodeType::All; } } else { self.board.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before); @@ -224,6 +264,7 @@ impl Grossmeister { return -SCORE_MATE + root_distance as Score } + self.store_transposition(transposition); alpha } -- cgit v1.2.3