zq99 / pgn2data

A library that converts a chess pgn file into a tabulated CSV data set.
GNU General Public License v3.0
15 stars 4 forks source link

Incorrect FENs #9

Open AlgoMenosVulgar opened 1 year ago

AlgoMenosVulgar commented 1 year ago

Hi zq99, really happy to have found your work. I am having some issues with the following: Imagine this link https://www.chess.com/game/live/76681276597?username=hikaru

which has the following PGN:

[Event "Live Chess"]
[Site "Chess.com"]
[Date "2023.05.01"]
[Round "?"]
[White "Hikaru"]
[Black "Blackmind96"]
[Result "1-0"]
[ECO "B20"]
[WhiteElo "3158"]
[BlackElo "2878"]
[TimeControl "180"]
[EndTime "5:02:13 PDT"]
[Termination "Hikaru won by resignation"]

1. e4 e6 2. d3 d5 3. Nd2 Nf6 4. Ngf3 c5 5. g3 Nc6 6. Bg2 g6 7. O-O Bg7 8. Re1
O-O 9. Qe2 a5 10. Nf1 b6 11. e5 Nd7 12. Bf4 a4 13. h4 a3 14. b3 b5 15. c3 Ba6
16. Rad1 d4 17. c4 Rb8 18. h5 bxc4 19. dxc4 Nb6 20. h6 Bh8 21. N1h2 Nd5 22. Bg5
Nce7 23. Bd2 Nb4 24. Bxb4 Rxb4 25. Ng4 Nf5 26. Nd2 d3 27. Qf3 Bb7 28. Ne4 Bxe4
29. Rxe4 Qg5 30. Qf4 Qxf4 31. Rxf4 Rd8 32. Be4 d2 33. Rf3 Rbb8 34. Rd3 Rxd3 35.
Bxd3 Nd4 36. Kf1 Nc6 37. f4 Nb4 38. Rxd2 Rd8 39. Ke2 Kf8 40. Bb1 Rxd2+ 41. Kxd2
Ke7 42. Nf2 f5 43. exf6+ Bxf6 44. Ne4 Bd4 45. Ng5 Bf2 46. g4 Bd4 47. Nxh7 Bf6
48. Nxf6 Kxf6 49. Ke3 Kf7 50. Ke4 Nc6 51. f5 exf5+ 52. gxf5 g5 53. h7 Kg7 54.
f6+ 1-0

after I get the two cvs with the details and moves I get the column "fen" and is like this:

1. rnbqkbnr/pppppppp/8/8/4P3/8/PPPP1PPP/RNBQKBNR
2. rnbqkbnr/pppp1ppp/4p3/8/4P3/8/PPPP1PPP/RNBQKBNR
3. ...
4. ...
...
Last. 8/6kP/2n2P2/2p3p1/2P1K3/pP6/P7/1B6

Now, this last one is impossible to analyze on stockfish python. It also fails if I put the fen into lichess.org directly.

The correct FEN that you can obtain from the original link says it should be: 8/6kP/2n2P2/2p3p1/2P1K3/pP6/P7/1B6 b - - 0 54

So, how to correct this? I can not do this manually, I am planning on analyzing 30k+ games and of course 100k+ FENs

brianch commented 1 year ago

From what I see, this happens because the FEN doesn't have the side to move. So if you for example paste it in board editors like Lichess or Scid, they will default to White to move, which is impossible because black is in check.

It would happen every time the position ends with black in check, like:

[Result "1-0"]
[Variant "Standard"]
[ECO "C62"]
[Opening "Ruy Lopez: Steinitz Defense"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 d6 4. Bxc6+ 1-0

Is there a particular reason why the FEN isn't complete? Since this info is in the color column, a workaround would be for users to adjust it using that, but it would be nice for the FEN to have all the fields (side, castling rights, en passant, etc.).

AlgoMenosVulgar commented 1 year ago

From what I see, this happens because the FEN doesn't have the side to move. So if you for example paste it in board editors like Lichess or Scid, they will default to White to move, which is impossible because black is in check.

It would happen every time the position ends with black in check, like:

[Result "1-0"]
[Variant "Standard"]
[ECO "C62"]
[Opening "Ruy Lopez: Steinitz Defense"]

1. e4 e5 2. Nf3 Nc6 3. Bb5 d6 4. Bxc6+ 1-0

Is there a particular reason why the FEN isn't complete? Since this info is in the color column, a workaround would be for users to adjust it using that, but it would be nice for the FEN to have all the fields (side, castling rights, en passant, etc.).

You are correct about that missing letter at the end specifying whose side is to play.