From e5a7d40ce5cab50941a38526c39688d0f1f263e1 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 21 Jan 2024 17:47:25 +0100 Subject: fix: correctly apply modulo to zobrist hash --- src/grossmeister/ttable.rs | 12 +++++++----- 1 file 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); } } -- cgit v1.2.3