Detect draws by 50-move-rule (and possibly 3-fold repetition)
mateon1 opened this issue · 2 comments
Currently, is_game_over
only detects checkmates, stalemates, and insufficient material, but not draws by the 50 move rule, or by 3-fold repetition.
Implementing the 50 move rule should be trivial, as the Chess
struct keeps track of the halfmoves counter.
(should also probably change legal_moves
and is_legal
to match this behavior.)
It's impossible to check for 3-fold repetition in is_game_over
given the way the Chess
struct is implemented, but maybe it's possible to expose a separate API, that given a starting position and a list of moves, returns whether any position repeated three times.
(I'm sure there's a better solution than keeping a hashmap of board FENs since the last irreversible move)
Technically the FIDE rules state that a draw is only forced at 75 reversible moves (if not check mate at the final move) and if the same position has appeared 5 times on consecutive alternative moves.
Article 9.6
With ZobristHash
from #40 we now have a useful building block.
Nonetheless I am hesitating on this one, because it requires adding a representation for games (rather than just position), and it seems the best structure is application dependent. Should it be a stack? Should it be a tree? Only the final position with some book keeping?