aboutsummaryrefslogtreecommitdiff
path: root/src/grossmeister
diff options
context:
space:
mode:
authoreug-vs <eugene@eug-vs.xyz>2024-01-21 17:47:25 +0100
committereug-vs <eugene@eug-vs.xyz>2024-01-21 17:47:25 +0100
commite5a7d40ce5cab50941a38526c39688d0f1f263e1 (patch)
tree2ee1ae0002b0aca4f0ca5a4f00ed505d3bfd4c46 /src/grossmeister
parent382cbe47672328d6bbb479f9fffc0f0413e92ada (diff)
downloadchessnost-e5a7d40ce5cab50941a38526c39688d0f1f263e1.tar.gz
fix: correctly apply modulo to zobrist hash
Diffstat (limited to 'src/grossmeister')
-rw-r--r--src/grossmeister/ttable.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/grossmeister/ttable.rs b/src/grossmeister/ttable.rs
index 2f673c9..b6b1a2c 100644
--- a/src/grossmeister/ttable.rs
+++ b/src/grossmeister/ttable.rs
@@ -44,13 +44,14 @@ impl Grossmeister {
/// Find current position in Transposition Table
/// This operation is safe from collisions since it compares the *full* hash
pub fn transposition(&self) -> Option<&TranspositionTableItem> {
- self.transposition_table.depth_preferred.get(&self.board.hash).and_then(|item| {
+ let hash = self.board.hash % TTABLE_SIZE;
+ self.transposition_table.depth_preferred.get(&hash).and_then(|item| {
if item.hash == self.board.hash {
Some(item)
} else {
None
}
- }).or(self.transposition_table.always_replace.get(&self.board.hash).and_then(|item| {
+ }).or(self.transposition_table.always_replace.get(&hash).and_then(|item| {
if item.hash == self.board.hash {
Some(item)
} else {
@@ -60,12 +61,13 @@ impl Grossmeister {
}
pub fn store_transposition(&mut self, transposition: TranspositionTableItem) {
- self.transposition_table.always_replace.insert(self.board.hash, transposition);
- if match self.transposition_table.depth_preferred.get(&self.board.hash) {
+ let hash = transposition.hash % TTABLE_SIZE;
+ self.transposition_table.always_replace.insert(hash, transposition);
+ if match self.transposition_table.depth_preferred.get(&hash) {
Some(existing_transposition) => transposition.depth >= existing_transposition.depth,
None => true,
} {
- self.transposition_table.depth_preferred.insert(self.board.hash, transposition);
+ self.transposition_table.depth_preferred.insert(hash, transposition);
}
}