From 248e679a3b744a21c4eecb05a66734b18acdd322 Mon Sep 17 00:00:00 2001 From: Thomas Marsh Date: Tue, 27 Feb 2024 12:14:44 -0500 Subject: [PATCH] Use non-zero initial Zobrist hash --- src/games/ttt.rs | 2 +- src/zobrist.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/games/ttt.rs b/src/games/ttt.rs index b64fd36..943f914 100644 --- a/src/games/ttt.rs +++ b/src/games/ttt.rs @@ -167,7 +167,7 @@ impl HashedPosition { pub fn new() -> Self { Self { position: Position::new(), - hashes: [0; 8], + hashes: [HASHES.initial(); 8], } } } diff --git a/src/zobrist.rs b/src/zobrist.rs index 3e7e618..4845030 100644 --- a/src/zobrist.rs +++ b/src/zobrist.rs @@ -66,6 +66,7 @@ impl ZobristHashMap { pub struct ZobristTable { hashes: [u64; N], + initial: u64, // We have a unique path via node_id in mcts, but other approaches might // benefit from having a path hash. See: Kishimoto, A., Müller, M., A // General Solution to the Graph History Interaction Problem. @@ -82,7 +83,10 @@ impl ZobristTable { *h = rng.gen::(); } - ZobristTable { hashes } + ZobristTable { + hashes, + initial: rng.gen::(), + } } fn hash(&self, index: usize) -> u64 { @@ -114,4 +118,9 @@ impl LazyZobristTable { pub fn hash(&self, index: usize) -> u64 { self.get_or_init().hash(index) } + + #[inline(always)] + pub fn initial(&self) -> u64 { + self.get_or_init().initial + } }