capicue / pgn

A chess file parser for ruby
MIT License
47 stars 23 forks source link

Bug: can not parse unfinished games #11

Closed Epigene closed 7 years ago

Epigene commented 7 years ago

Hi!

The gem (v0.2.0) seems unable to parse incomplete games. Adding a result portion solves this.

Parses:

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2017.11.12"]
[White "piguik"]
[Black "Epigene"]
[Result "0-1"]
[ECO "B54"]
[WhiteElo "1325"]
[BlackElo "1375"]
[TimeControl "300"]

1. e4 a6 2. Bc4 a5 3. Ne2 a4 4. O-O Ra7
5. e5 f5 6. exf6 a5 0-1

Does not parse:

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2017.11.12"]
[White "piguik"]
[Black "Epigene"]
[Result "0-1"]
[ECO "B54"]
[WhiteElo "1325"]
[BlackElo "1375"]
[TimeControl "300"]

1. e4 a6 2. Bc4 a5 3. Ne2 a4 4. O-O Ra7
5. e5 f5 6. exf6 a5
tobiasvl commented 7 years ago

The PGN specification section 8.2.6 says that the value in the "Result" tag should be repeated at the end of the movetext:

Each movetext section has exactly one game termination marker; the marker always occurs as the last element in the movetext. The game termination marker is a symbol that is one of the following four values: "1-0" (White wins), "0-1" (Black wins), "1/2-1/2" (drawn game), and "*" (game in progress, result unknown, or game abandoned). Note that the digit zero is used in the above; not the upper case letter "O". The game termination marker appearing in the movetext of a game must match the value of the game's Result tag pair. (While the marker appears as a string in the Result tag, it appears as a symbol without quotes in the movetext.)

So this behavior seems entirely correct to me.

Epigene commented 7 years ago

Thanks for the link to the spec. Perusing it I learned that a "*" symbol ought to be used do show an incomplete game.

This ought to parse (can't check at the moment):

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2017.11.12"]
[White "piguik"]
[Black "Epigene"]
[Result "0-1"]
[ECO "B54"]
[WhiteElo "1325"]
[BlackElo "1375"]
[TimeControl "300"]

1. e4 a6 2. Bc4 a5 3. Ne2 a4 4. O-O Ra7
5. e5 f5 6. exf6 a5 *