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.4k stars 526 forks source link

epd parser issue when given a fen #1080

Closed Tilps closed 5 months ago

Tilps commented 5 months ago

I happened to notice that some .epd files on the internet are not actually a file containing epd format items. Instead they are actually just a collection of fen format items.

file.readlines() -> board.set_epd(line) - in this case doesn't given an error, but also doesn't capture the 50 move rule clock information.

Based on my understanding of the epd format, it should be an error as opcodes must start with a letter, never an integer. However, given the code is already somewhat lenient, maybe instead the case of input being a full fen (and not actually an epd) should be special cased and just passed onward to set_fen instead.

niklasf commented 5 months ago

Thanks for reporting. The issue appears to be that the move numbers are parsed as valid EPD operations:

board.set_epd("4k3/8/8/8/8/8/8/3K4 b - - 12 13")
{'12': 13}

just like

>>> board.set_epd("4k3/8/8/8/8/8/8/3K4 b - - foo 1")
{'foo': 1}

However the specification says that opcodes are supposed to start with a letter (not a digit), so it would be correct to reject the former. Will fix. With the potential for confusion with legit opcodes, I think I'd prefer not automatically falling back to FEN.