bhlangonijr / chesslib

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

Why the game object initialization depends on player property during parsing pgn? #99

Open intothephone opened 2 years ago

intothephone commented 2 years ago

"The PGN parsing process should not depend on property orders." I had lots of pgn files in which "Result" propery before "White" or "Black" property, for example:

[Event "1st World U20 ch"] [Site "Birmingham ENG"] [Date "1951.06.20"] [EventDate "1951.??.??"] [Round "9"] [Result "1-0"] [White "Bent Larsen"] [Black "Lionel Joyner"] [ECO "C30"] [WhiteElo "?"] [BlackElo "?"] [PlyCount "63"]

  1. e4 e5 2. f4 Bc5 3. Nf3 d6 4. c3 Bg4 5. fxe5 dxe5 6. Qa4+ Bd7 7. Qc2 Nc6 8. b4 Bd6 9. Be2 Qe7 10. Na3 a5 11. b5 Nd8
  2. Nc4 f6 13. O-O Nh6 14. d4 Nhf7 15. a4 O-O 16. Nxd6 Nxd6
  3. Ba3 N8f7 18. c4 exd4 19. c5 Qxe4 20. Bd3 Qe3+ 21. Kh1 Nxb5
  4. axb5 c6 23. Bxh7+ Kh8 24. Nh4 Ne5 25. Rae1 Qh6 26. Ng6+ Nxg6 27. Bxg6 Be8 28. Bf5 cxb5 29. c6 b4 30. Bc1 g5 31. c7 Bc6
  5. Re7 1-0

After parsing, the result is "ONGOING", that is incorrect.

The code from "GameLoader.java", line 153:

case "result": if (game != null) { GameResult r = GameResult.fromNotation(p.value); game.setResult(r); } break;

here game is null, because game object will be initialized only after parsing "White" or "Black" property. The result is incorrect. Of course after changing the property order in file, it works well.

dcolazin commented 1 year ago

Working on it!

dcolazin commented 1 year ago

Done.