SebLague / Chess-Challenge

Create your own tiny chess bot!
https://www.youtube.com/watch?v=Ne40a5LkK6A
MIT License
1.78k stars 1.07k forks source link

Include Ply in Zobrist Hash #412

Closed kesslwovv closed 11 months ago

kesslwovv commented 11 months ago

As far as i can tell, the Ply (move count) is not encorporated into the Zobrist Key.

This is not crucial but it is annoying, because it can change evaluation when using a hash map.

Here is how I encountered this issue:
When I started implementing Alpha-Beta pruning, I kept the non-pruning version (with hashmap optimisation) to compare the evaluations and ensure that the new behaviour was correct. however in rare cases this hashmap optimisation changed the result, which was because later states, that could also be reached through a shorter move sequence, were evaluated at a shallower depth but still generated the same key.

WhiteMouse1 commented 11 months ago

You need to track the depth yourself in your own transposition table implementation. Zobrist key cannot contain anything except Zobrist hash or else it will not be a Zobrist key anymore.

0qln commented 11 months ago

Maybe create a hash struct with the evaluation and the depth that the move was searched to. Then you could make educated decisions in your search function, wether to use a hash or not.

kesslwovv commented 11 months ago

thanks