hash collision issue?
Posted: 18 Feb 2008, 07:32
Hi all!
I am writing my bitboards based chess engine as a hobby, and I've got an issue with my hash tables. I am not sure if I am doing anything wrong or if I even have a bug, but I need some explanations
My hash table size is 20940347 (prime number in the 20 millions). My hash keys are 64 bits numbers.
As my alpha beta is computing, I "new" pointers who do not correspond to any hash table entry. I have the computer play a few moves and after having newed roughly 5400 entries, I've got hash collision.
Basically my engine has found two totally different positions (I am sure they are totally different, as I can see them in the debugger) with two totally different hash keys (I am sure of that too), that give the same reminder when they are divided by 20940347, hence that give the same index to my hash table.
These numbers are as follows:
3843009106291839884 % 20940347 = 17414108
7315253179216087815 % 20940347 = 17414108
So I get the same index in the table and I am about to overwrite the previous value. Shall I implement a strategy to overcome this issue (like linked list) or is this absolutely not normal and should be very unlikely?
I use Zobrist keys, and compute my first hash key (the position to search with my alpha beta) by visiting every square, and hashing on with the following random zobrist keys:
m_ZobristKey[pieceType][colour][square]
then as I create positions by generating moves, I hash in and out, as everybody does in the literature (I handle the different cases of captures, promotions, en passant, castling, regular moves, etc).
If I keep running the program, collisions get more and more frequent...
I use two random 32 bits appended to create a 64 hash key.
To get the random 32 bits, I use the algorithm given by Knuth, the art of computer programming, vol. 2, pp. 26-27.
So I am wondering:
Is it a hashing bug?
Is it a randomness bug?
Is it both?
Is it even a bug?
Thanks in advance!
I am writing my bitboards based chess engine as a hobby, and I've got an issue with my hash tables. I am not sure if I am doing anything wrong or if I even have a bug, but I need some explanations
My hash table size is 20940347 (prime number in the 20 millions). My hash keys are 64 bits numbers.
As my alpha beta is computing, I "new" pointers who do not correspond to any hash table entry. I have the computer play a few moves and after having newed roughly 5400 entries, I've got hash collision.
Basically my engine has found two totally different positions (I am sure they are totally different, as I can see them in the debugger) with two totally different hash keys (I am sure of that too), that give the same reminder when they are divided by 20940347, hence that give the same index to my hash table.
These numbers are as follows:
3843009106291839884 % 20940347 = 17414108
7315253179216087815 % 20940347 = 17414108
So I get the same index in the table and I am about to overwrite the previous value. Shall I implement a strategy to overcome this issue (like linked list) or is this absolutely not normal and should be very unlikely?
I use Zobrist keys, and compute my first hash key (the position to search with my alpha beta) by visiting every square, and hashing on with the following random zobrist keys:
m_ZobristKey[pieceType][colour][square]
then as I create positions by generating moves, I hash in and out, as everybody does in the literature (I handle the different cases of captures, promotions, en passant, castling, regular moves, etc).
If I keep running the program, collisions get more and more frequent...
I use two random 32 bits appended to create a 64 hash key.
To get the random 32 bits, I use the algorithm given by Knuth, the art of computer programming, vol. 2, pp. 26-27.
So I am wondering:
Is it a hashing bug?
Is it a randomness bug?
Is it both?
Is it even a bug?
Thanks in advance!