aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grossmeister/search.rs41
1 files changed, 41 insertions, 0 deletions
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
}