aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2023-01-25 09:34:25 +0300
committereug-vs <eugene@eug-vs.xyz>2023-01-25 09:34:25 +0300
commita905ddb6104849d561a2559182d3c09735ebf5ef (patch)
tree34b3d2b4876a3747b233d7e1dd0c0b614702ab55
parentaabc81cf486d4ffe2696609c0d27e5bfa60c80eb (diff)
downloadchessnost-a905ddb6104849d561a2559182d3c09735ebf5ef.tar.gz
feat!: check if transposition hash truly matches
-rw-r--r--src/board/engine.rs19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/board/engine.rs b/src/board/engine.rs
index d550418..b6daacf 100644
--- a/src/board/engine.rs
+++ b/src/board/engine.rs
@@ -135,7 +135,7 @@ impl Board {
match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] {
Some(item) => {
- if item.node_type == NodeType::PV {
+ if item.node_type == NodeType::PV && item.hash == self.hash {
moves.insert(0, item.best_move);
}
}
@@ -158,13 +158,6 @@ impl Board {
self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
if score >= beta {
- self.transposition_table[(self.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem {
- hash: self.hash,
- best_move: mov,
- depth: depth_left, // TODO: should be actual depth searched
- node_type: NodeType::Cut,
- score,
- });
return (beta, principal_variation);
}
if score > alpha {
@@ -172,6 +165,14 @@ impl Board {
principal_variation = Vec::with_capacity(depth_left as usize);
principal_variation.push(mov);
principal_variation.append(&mut subtree_pv);
+
+ self.transposition_table[(self.hash % TTABLE_SIZE) as usize] = Some(TranspositionTableItem {
+ hash: self.hash,
+ best_move: mov,
+ depth: depth_left, // TODO: should be actual depth searched
+ node_type: NodeType::PV,
+ score,
+ });
}
} else {
self.unmake_move(mov, captured_piece, ep_target_before, castling_rights_before, hash_before);
@@ -198,7 +199,7 @@ impl Board {
match self.transposition_table[(self.hash % TTABLE_SIZE) as usize] {
Some(item) => {
- if item.node_type == NodeType::PV {
+ if item.node_type == NodeType::PV && item.hash == self.hash {
moves.insert(0, item.best_move);
}
}