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.42k stars 529 forks source link

Promotions in pgn without equal sign #24

Closed ghost closed 9 years ago

ghost commented 9 years ago

I used your library for pgn parsing and got exceptions then try to parse some pgns with promotion moves like:

e8Q e8Q+ e8Q#

I think it's because it's doesn't have equal sign and there moves throws no exception:

e8=Q e8=Q+ e8=Q#

niklasf commented 9 years ago

Hi @chezstov, that is correct. Where do these PGN files come from? Can you provide a complete example?

Generally I don't think we must insist on the =, so we could make the parser a bit more forgiving.

ghost commented 9 years ago

So, this is an example:

[Event "It (open)"] [Site "Aschach (Austria)"] [Date "2011.12.26"] [Round "1"] [White "Ennsberger Ulrich (AUT)"] [Black "Koller Hans-Juergen (AUT)"] [Result "0-1"] [ECO "A45"] [WhiteElo "2373"] [BlackElo "2052"] [ID ""] [FileName ""] [Annotator ""] [Source ""] [Remark ""]

1.d4 Nf6 2.Bg5 c5 3.d5 Ne4 4.Bf4 Qb6 5.Nd2 Nxd2 6.Bxd2 e6 7.Bc3 d6 8.e4 e5 9.a4 Be7 10.a5 Qc7 11.f4 f6 12.f5 g6 13.Bb5+ Bd7 14.Bc4 gxf5 15.Qh5+ Kd8 16.exf5 Qc8 17.g4 Na6 18.Ne2 b5 19.axb6 axb6 20.O-O Nc7 21.Qf7 h5 22.Qg7 Rf8 23.gxh5 Ne8 24.Rxa8 Nxg7 25.Rxc8+ Kxc8 26.Ng3 Rh8 27.Be2 Be8 28.Be1 Nxh5 29.Bxh5 Bxh5 30.Nxh5 Rxh5 31.h4 Bf8 32.c4 Bh6 33.Bg3 Be3+ 34.Kg2 Kb7 35.Kh3 b5 36.b3 b4 37.Kg4 Rh8 38.Kf3 Bh6 39.Bf2 Ra8 40.Kg4 Bf4 41.Kh5 Ra3 42.Kg6 Rxb3 43.h5 Rf3 44.h6 Bxh6 45.Kxh6 Rxf5 46.Kg6 Rf4 47.Kf7 e4 48.Re1 Rxf2 49.Ke6 Kc7 50.Rh1 b3 51.Rh7+ Kb6 52.Kxd6 b2 53.Rh1 Rd2 54.Rh8 e3 55.Rb8+ Ka5 56.Kxc5 Ka4 57.d6 e2 58.Re8 b1Q 0-1

niklasf commented 9 years ago

Thanks. Did you download this somewhere or did you use a program to create it? Just to get an idea where files like this are coming from.

It's late here, already. I'll adjust the parser tomorrow.

ghost commented 9 years ago

This game from https://github.com/rozim/ChessData

niklasf commented 9 years ago

I have just committed this. It will be included in the next release. In the meantime I'll check if there are other incompabilities with rozim/ChessData.