Noob question on Zobrist Hashing and TT
Posted: Thu Sep 10, 2020 8:23 am
Hi Guys!
I'm going to implement the very first transposition table in my life basing on this tutorial by Bruce Moreland:
https://web.archive.org/web/20071031100 ... ashing.htm
I don't want to be distracted by incrementally hashing whatever is changing within a position and just hash the position from scratch every time.
(I know it's weird and slows down the performance)
I've been walking through HGM's post "data structures choice for TT" and was really impressed by this quote
(assuming bitboard board representation)
My questions are:
1. Is this gonna work?
2. What would be the limitations?
THANKS IN ADVANCE!
I'm going to implement the very first transposition table in my life basing on this tutorial by Bruce Moreland:
https://web.archive.org/web/20071031100 ... ashing.htm
I don't want to be distracted by incrementally hashing whatever is changing within a position and just hash the position from scratch every time.
(I know it's weird and slows down the performance)
I've been walking through HGM's post "data structures choice for TT" and was really impressed by this quote
So as far as the hashing would be running from scratch I want to make it as fast as possible, so here's a draft of my hashing function:In practice the randomness of the Zobrist keys doesn't have to be very good; Zobrist hashing is a very forgiving scheme. People even have tried deriving the keys from just 12 truly random numbers (for the piece types), and derive the keys from those by making 64 bit-rotated versions of those for the squares. This seems to work fine too, even though rotating a bit pattern can hardly be called a good random generator.
(assuming bitboard board representation)
Code: Select all
// generate position key
static inline U64 identify_position()
{
// position key
U64 position_key = 0ULL;
// hash bitboards
for (int bb_piece = P; bb_piece <= k; bb_piece++)
position_key ^= bitboards[bb_piece];
// hash occupancies
position_key ^= occupancies[white];
position_key ^= occupancies[black];
position_key ^= occupancies[both];
// hash side
position_key ^= side;
// hash enpassant
position_key ^= enpassant;
// hash castling
position_key ^= castling;
return position_key;
}
1. Is this gonna work?
2. What would be the limitations?
THANKS IN ADVANCE!