niklasf / python-chess

A chess library for Python, with move generation and validation, PGN parsing and writing, Polyglot opening book reading, Gaviota tablebase probing, Syzygy tablebase probing, and UCI/XBoard engine communication
https://python-chess.readthedocs.io/en/latest/
GNU General Public License v3.0
2.43k stars 531 forks source link

Some illegal positions are shown as valid #707

Closed ipostr08 closed 3 years ago

ipostr08 commented 3 years ago

Some examples:

3R4/8/q4k2/2B5/1NK5/3b4/8/8 w - - 0 1
2Nq4/2K5/1b6/8/7R/3k4/7P/8 w - - 0 1
5R2/2P5/8/4k3/8/3rK2r/8/8 w - - 0 1

Common theme: king under attack by two different pieces when it couldn't result from a discovery check. The problem is that these positions crash Stockfish or cause it to suggest an illegal move.

niklasf commented 3 years ago

Thanks for reporting. In general, detecting unreachable positions is out of scope, but at least all of the positions that give Stockfish trouble should be detected.

niklasf commented 3 years ago

The issue appears to be that Stockfish (rightfully) never considers checking sliders to be protected by another checking slider:

https://github.com/official-stockfish/Stockfish/blob/8630d03dd4e1ec7e492ddf6c40d9d9e4cdba2a58/src/movegen.cpp#L328-L332

To be fixed in:

For variants:

niklasf commented 3 years ago

Released in v1.3.2.