lichess-org / lila

♞ lichess.org: the forever free, adless and open source chess server ♞
https://lichess.org
GNU Affero General Public License v3.0
15.58k stars 2.28k forks source link

Wrong PGN export from study with multiple comments per node #15939

Open Siderite opened 2 months ago

Siderite commented 2 months ago

Exact URL of where the bug happened

https://lichess.org/study/GJ5NRo9a/t7QR44fO

Steps to reproduce the bug

  1. Export the chapter PGN
  2. Try to import it in Analysis or anywhere

What did you expect to happen?

Exported PGN is correct

What happened instead?

PGN fails to export move 12...a5, resulting in an invalid PGN

Operating system

Windows 11

Browser and version (or alternate access method)

Brave

Additional information

Particular node that causes the issue can be found at path "/?WG)8aP8GVNG8P?.>NF(6`N'*_b-=UM(']H&4^V=ENU19"

The simplified PGN to the move is this: 1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nf3 Nxe4 5. d4 d5 6. Bd3 Bd6 7. O-O O-O 8. c4 c6 9. Re1 Bf5 10. Qb3 Qd7 11. c5 Bc7 12. g3 {Torch v2: 839058Mn} {[#]Testing out the Nakamura-Nepo game from the 2024 Candidates!} a5 13. Nbd2

Siderite commented 2 months ago

There are multiple chapters that are exported wrong in that study.

kraktus commented 2 months ago

I cannot reproduce with the simplified example

https://lichess.org/study/a27kFcjo/MrbgVpLQ

copy PGN

[Event "multi-comment export #15939: Chapter 1"]
[Site "https://lichess.org/study/a27kFcjo/MrbgVpLQ"]
[Result "*"]
[Variant "Standard"]
[ECO "C42"]
[Opening "Petrov's Defense: Classical Attack, Staunton Variation"]
[Annotator "https://lichess.org/@/Solal35"]
[UTCDate "2024.08.26"]
[UTCTime "09:41:44"]

1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nf3 Nxe4 5. d4 d5 6. Bd3 Bd6 7. O-O O-O 8. c4 c6 9. Re1 Bf5 10. Qb3 Qd7 11. c5 Bc7 12. g3 { [#]Testing out the Nakamura-Nepo game from the 2024 Candidates! } { Torch v2: 839058Mn } 12... a5 13. Nbd2 *

Export chapter PGN

[Event "multi-comment export #15939: Chapter 1"]
[Site "https://lichess.org/study/a27kFcjo/MrbgVpLQ"]
[Result "*"]
[Variant "Standard"]
[ECO "C42"]
[Opening "Petrov's Defense: Classical Attack, Staunton Variation"]
[Annotator "https://lichess.org/@/Solal35"]
[UTCDate "2024.08.26"]
[UTCTime "09:41:44"]

1. e4 e5 2. Nf3 Nf6 3. Nxe5 d6 4. Nf3 Nxe4 5. d4 d5 6. Bd3 Bd6 7. O-O O-O 8. c4 c6 9. Re1 Bf5 10. Qb3 Qd7 11. c5 Bc7 12. g3 { [#]Testing out the Nakamura-Nepo game from the 2024 Candidates! } { Torch v2: 839058Mn } 12... a5 13. Nbd2 *
lenguyenthanh commented 2 months ago

I looked at this the other day and there is definitely something wrong with our parser. Basically, this should work pgn ==parse(pgn).toPgn, but it doesn't.

https://github.com/lenguyenthanh/scala-examples/commit/1676ecd292883bfa8cc313b95d1a4da3bdf38197

Siderite commented 2 months ago

Note that the PGN exported from LiChess Tools in the client was OK, imported OK and yielded no issues. Which means at least getting the data from the server to the move tree works fine, and indeed the study works just fine. It's the string output that is the issue.

lenguyenthanh commented 2 months ago

@Siderite could you send me the exported pgn by LiChess Tools?

Siderite commented 2 months ago
[White "Torch Openings"]
[Black "1.e4 with theory review"]
[Date "2024.03.25"]
[Result "*"]
[Annotator "GM Matthew Sadler"]
[Site "https://lichess.org/study/GJ5NRo9a/t7QR44fO"]
[UTCDate "2024.08.26"]
[UTCTime "12:44:53"]
 {305093Mn produced a main line in the Berlin endgame.}
1. e4 e5 2. Nf3 Nf6 3. Nxe5 {Produced after 244243Mn} d6 4. Nf3 Nxe4 5. d4 d5 6. Bd3 Bd6 7. O-O O-O 8. c4 c6 9. Re1 Bf5 10. Qb3 Qd7 11. c5 Bc7 12. g3 {Torch v2: 839058Mn} {[#]Testing out the Nakamura-Nepo game from the 2024 Candidates!} a5 (13. Nbd2 Be6 14. Qxb7 Nxf2 15. Bxh7+ Kxh7 16. Qxa8 Nh3+ 17. Kg2 Bg4 18. Qb7 Re8 19. Qb3 {Nakamura,H (2789)-Nepomniachtchi,I (2758) Toronto, Canada 2024}) 13. Nbd2 Be6 14. Qxb7 Nxf2 15. Bxh7+ Kxh7 16. Ng5+ (16. Qxa8) 16... Kg8 17. Qxa8 Nh3+ 18. Nxh3 Bxh3 19. Nf3 Qf5 20. Ng5 Qg4 21. Nxh3 Bxg3 22. Nf2 Bxf2+ 23. Kxf2 Qf5+ 24. Kg3 Qg6+ 25. Kf3 Qh5+ 26. Kg3 {0.00/76}

copied to the offending node and all variations following it.

But note that this is my own rendering of the node data, so it might not help much.

Siderite commented 2 months ago

Lol! I just realized that it's not importing it. Geez! Steered you wrong. I remember that it was fine, though.

Yes, the children are all wrong. node with ply 23 has children with ply 24 and 25.

lenguyenthanh commented 2 months ago

ah, thanks any way! We may need to ask the user for the original pgn. But I'll try to debug it first.