bhlangonijr / chesslib

chess library for legal move generation, FEN/PGN parsing and more
Apache License 2.0
223 stars 78 forks source link

PGN changes when loading then running game.toPgn #109

Open ghost opened 1 year ago

ghost commented 1 year ago

This is the attributes part of the original PGN from the chess.com API:

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2021.08.31"]
[Round "-"]
[White "Malzawar"]
[Black "edwinuchiha"]
[Result "1-0"]
[CurrentPosition "4k2Q/4n2p/8/5p2/6p1/4B1P1/P4P1P/4NRK1 b - -"]
[Timezone "UTC"]
[ECO "A10"]
[ECOUrl "https://www.chess.com/openings/English-Opening-1...b6-2.d4-Bb7"]
[UTCDate "2021.08.31"]
[UTCTime "23:22:16"]
[WhiteElo "881"]
[BlackElo "840"]
[TimeControl "600"]
[Termination "Malzawar won by resignation"]
[StartTime "23:22:16"]
[EndDate "2021.08.31"]
[EndTime "23:31:01"]
[Link "https://www.chess.com/game/live/24191220599"]

When loading it into a game and then using game.toPgn(false, true) the resulting PGN differs:

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2021.08.31"]
[Round "1"]
[White "Malzawar"]
[Black "edwinuchiha"]
[Result "1-0"]
[PlyCount "63"]
[Termination "unterminated"]
[TimeControl "600"]
[ECO "A10"]
[WhiteElo "881"]
[BlackElo "840"]
[Timezone "UTC"]
[UTCTime "23:22:16"]
[CurrentPosition "4k2Q/4n2p/8/5p2/6p1/4B1P1/P4P1P/4NRK1 b - -"]
[EndTime "23:31:01"]
[StartTime "23:22:16"]
[UTCDate "2021.08.31"]
[ECOUrl "https://www.chess.com/openings/English-Opening-1...b6-2.d4-Bb7"]
[EndDate "2021.08.31"]
[Link "https://www.chess.com/game/live/24191220599"]

A list of differences (original vs output):

  1. [Round "-"] vs [Round "1"]
  2. [Termination "Malzawar won by resignation"] vs [Termination "unterminated"]

Difference 1. is fine as it is up to interpretation whether round 1 of a total of 1 rounds means that there are no meaningful rounds to count or that there is 1 round.

Difference 2. is just plain wrong. The Result field is (1-0) and game.getResult() returns WHITE_WON, which implies that the game terminated somehow.