KYLChiu / sporkfish

Chess engine in Python
MIT License
5 stars 0 forks source link

[Feature] Endgame tablebases handle repetition #108

Closed KYLChiu closed 6 months ago

KYLChiu commented 7 months ago

Imagine an endgame position (pos 1) where we return a result from the endgame database, forcing the opponent move to pos 2. Now we fetch another move from the database, which happens to a non-forcing move (but a winning move nonetheless), allowing the opponent to return to position 1.

Since move order is deterministic, we will again fetch the the move that forces the opponent to return to position 2. This process will happen thrice until we draw by threefold repetition, even if these are winning moves - because the database guarantees it.

This happens because the database only considers if the move will eventually lead to mate, which means repeating moves will be considered winning as well. To remedy this we can use DTZ (depth to zero).