chesskit-app / chesskit-swift

♟️ Swift package for implementing chess logic.
MIT License
7 stars 6 forks source link

Add support for draw by repetition #15

Open pdil opened 2 months ago

pdil commented 2 months ago

If an identical position is reached 3 times, a .draw(.repetition) result should be published by Board. The rules that must be implemented are described here: https://en.wikipedia.org/wiki/Threefold_repetition#Statement_of_the_rule

[!IMPORTANT] Care must be taken in the design and implementation of this feature (algorithm/data structure) to avoid any performance bottlenecks when determining if a position has been reached 3 times.

Further Consideration

Since FIDE has separate rules for threefold and fivefold repetition, it may be beneficial to publish both scenarios through the API so the consumer can react as they see fit.

An example could be augmenting the Board.EndResult.DrawType enum to have following two extra cases (in lieu of just .repetition):

case threefoldRepetition
case fivefoldRepetition