aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/grossmeister/search.rs55
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);