Hi,
I'm building a checkers program, but I have a problem. I implemented a transposition table where SIZE = 600000 entries. I use Zobrist keys for hashing, which I calculate like this:
public ulong GetHashKey()
{
uint bit;
ulong hashKey = 0;
for (int i = 0; i < 32; i++)
{
bit = (uint)1 << i;
if ((p1 & bit) > 0) hashKey = hashKey ^ random[0, i];
if ((k1 & bit) > 0) hashKey = hashKey ^ random[1, i];
if ((p2 & bit) > 0) hashKey = hashKey ^ random[2, i];
if ((k2 & bit) > 0) hashKey = hashKey ^ random[3, i];
}
return hashKey;
}
The index in the hashtable array is calculated using
index = board.GetHashKey() % SIZE
I calculate the random numbers like this:
Random r = new Random((int)DateTime.Now.Ticks);
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 32; j++)
{
ulong randNumber =
(ulong) r.Next() ^
((ulong)r.Next() << 15) ^
((ulong)r.Next() << 30) ^
((ulong)r.Next() << 45) ^
((ulong)r.Next() << 60);
Console.WriteLine(randNumber);
random[i, j] = randNumber;
}
}
Now somehow different boards keep coming up with the same hash keys. When my hashtable has about 10000 entries filled, it has collided with some 500 (5%) different boards with the same hashkey....
Question: is this normal? Should I just ignore collisions and keep on recursing down my Negamax function? Does anybody have any idea how to avoid these collisions?
Every article I read on this subject says it's highly improbable that hash keys will collide, but my app collides in 5% of all cases.
BTW: I don't make any distinction in side to move..
Thanks,
Edo