Idea to virtually zero hash collisions
Posted: Tue Mar 15, 2016 8:14 am
hi
In my struggle to correct and perfect my hash function for my perft,i have stumbled upon a discovery.Not sure if this is novel.
With only a 32 bit hashkey i was able to get this with only 1 hash collision,i know there should be many more with this amount of nodes.
The Starting HashKey = 12888282270356907191
Number of nodes depth (1) = 20
Number of nodes depth (2) = 400
Number of nodes depth (3) = 8902
Number of nodes depth (4) = 197281
Number of nodes depth (5) = 4865609
Number of nodes depth (6) = 119060324
Number of nodes depth (7) = 3195901860
Number of nodes depth (8) = 84998978956
Number of nodes depth (9) = 2439530234167
Number of nodes depth (10) = 69352859712417
Number of the hashnodes = 66691435746827
Number of Hash Collisions = 1
I used a function to check the position to see if the position is similar with the same hashkey to detect the collision.There was only 1 in this case.
The way i did it was as follows.The hashkey is dynamic,it changes,for example if i make a move and unmake,the hashkey changes,if i make the same move again,it's different.
For perft there is no problem with the hashnodes,the nodes are correct.And the amount of nodes detected in hash is even more than with my regular approach.The speed is also as fast if not faster.
I used a temp hashkey in my movegenerator.
In my movelist structure i have for example these 2...
struc movelist
{
.movelist rq 246
.hashkey rq 246
..
..
and i don't calculate the hashkeys in make/unmake,but in my move generator.I use a temp hashkey
if UseHash eq 1
mov rax,[my.hashkey]
mov [my.tempkey],rax
end if
and then later...
if UseHash eq 1
mov rcx,[my.tempkey]
mov [make.hashkey + r10 + r14],rcx
end if
mov qword [make.movelist + r10 + r14],rsi
and then in my make/unmake function i use it as follows... in make...
mov rax,[make.hashkey + rbx + r14]
mov [my.hashkey],rax
and in unmake...
mov [my.hashkey],0
For perft this works perfect,correct nodes,virtually no hash collisions,optimal hash detection,good speed.
Any comments how this could work in my chess engine,with not having the same hashkey everytime for the same position,is this usable in a real life chess engine,or just good for my perft function?
In each hashkey i would save the move anyway,so it should not be a problem ?!
Best Regards
Izak
In my struggle to correct and perfect my hash function for my perft,i have stumbled upon a discovery.Not sure if this is novel.
With only a 32 bit hashkey i was able to get this with only 1 hash collision,i know there should be many more with this amount of nodes.
The Starting HashKey = 12888282270356907191
Number of nodes depth (1) = 20
Number of nodes depth (2) = 400
Number of nodes depth (3) = 8902
Number of nodes depth (4) = 197281
Number of nodes depth (5) = 4865609
Number of nodes depth (6) = 119060324
Number of nodes depth (7) = 3195901860
Number of nodes depth (8) = 84998978956
Number of nodes depth (9) = 2439530234167
Number of nodes depth (10) = 69352859712417
Number of the hashnodes = 66691435746827
Number of Hash Collisions = 1
I used a function to check the position to see if the position is similar with the same hashkey to detect the collision.There was only 1 in this case.
The way i did it was as follows.The hashkey is dynamic,it changes,for example if i make a move and unmake,the hashkey changes,if i make the same move again,it's different.
For perft there is no problem with the hashnodes,the nodes are correct.And the amount of nodes detected in hash is even more than with my regular approach.The speed is also as fast if not faster.
I used a temp hashkey in my movegenerator.
In my movelist structure i have for example these 2...
struc movelist
{
.movelist rq 246
.hashkey rq 246
..
..
and i don't calculate the hashkeys in make/unmake,but in my move generator.I use a temp hashkey
if UseHash eq 1
mov rax,[my.hashkey]
mov [my.tempkey],rax
end if
and then later...
if UseHash eq 1
mov rcx,[my.tempkey]
mov [make.hashkey + r10 + r14],rcx
end if
mov qword [make.movelist + r10 + r14],rsi
and then in my make/unmake function i use it as follows... in make...
mov rax,[make.hashkey + rbx + r14]
mov [my.hashkey],rax
and in unmake...
mov [my.hashkey],0
For perft this works perfect,correct nodes,virtually no hash collisions,optimal hash detection,good speed.
Any comments how this could work in my chess engine,with not having the same hashkey everytime for the same position,is this usable in a real life chess engine,or just good for my perft function?
In each hashkey i would save the move anyway,so it should not be a problem ?!
Best Regards
Izak