Skip to content

Commit

Permalink
Use non-zero initial Zobrist hash
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasmarsh committed Feb 27, 2024
1 parent 45593dd commit 248e679
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/games/ttt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl HashedPosition {
pub fn new() -> Self {
Self {
position: Position::new(),
hashes: [0; 8],
hashes: [HASHES.initial(); 8],
}
}
}
Expand Down
11 changes: 10 additions & 1 deletion src/zobrist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ impl<T> ZobristHashMap<T> {

pub struct ZobristTable<const N: usize> {
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.
Expand All @@ -82,7 +83,10 @@ impl<const N: usize> ZobristTable<N> {
*h = rng.gen::<u64>();
}

ZobristTable { hashes }
ZobristTable {
hashes,
initial: rng.gen::<u64>(),
}
}

fn hash(&self, index: usize) -> u64 {
Expand Down Expand Up @@ -114,4 +118,9 @@ impl<const N: usize> LazyZobristTable<N> {
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
}
}

0 comments on commit 248e679

Please sign in to comment.