bhlangonijr / chesslib

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

Coudn't parse destination square[cxd8Q]: CXD8Q #8

Closed alexmatv70 closed 5 years ago

alexmatv70 commented 5 years ago

Hi,

Just tried to parse pgn from 34th European Club Cup (http://chess-results.com/tnr373918.aspx?lan=11) and got the following exception:

Exception in thread "main" com.github.bhlangonijr.chesslib.move.MoveConversionException: Coudn't parse destination square[cxd8Q]: CXD8Q
    at com.github.bhlangonijr.chesslib.move.MoveList.encodeSanToMove(MoveList.java:581)
    at com.github.bhlangonijr.chesslib.move.MoveList.addSanMove(MoveList.java:492)
    at com.github.bhlangonijr.chesslib.move.MoveList.addSanMove(MoveList.java:468)
    at com.github.bhlangonijr.chesslib.move.MoveList.loadFromSan(MoveList.java:529)
    at com.github.bhlangonijr.chesslib.game.Game.loadMoveText(Game.java:872)
    at com.github.bhlangonijr.chesslib.game.Game.loadMoveText(Game.java:694)
    at Parse.main(Parse.java:12)

pgn is attached cup.pgn.zip

Code fragment is from readme

       PgnHolder pgn = new PgnHolder("D:\\Projects\\chess\\cup.pgn");
        pgn.loadPgn();
        for (Game game: pgn.getGame()) {
            game.loadMoveText();
            MoveList moves = game.getHalfMoves();
            Board board = new Board();
            //Replay all the moves from the game and print the final position in FEN format
            for (Move move: moves) {
                board.doMove(move);
            }
        }
bhlangonijr commented 5 years ago

Hi @alexmatv70, this bug has been fixed in version 1.1.4 chesslib was expecting an equal sign to identify pawn promotions. The absence of it and the extra char for the promotion was causing the error reported. It's fixed to work without the equal sign now. Would you validate and close the issue. Thanks!

alexmatv70 commented 5 years ago

Yes, this case is fixed in 1.1.4 but there are 3 other similar exceptions on the same data:

Exception: com.github.bhlangonijr.chesslib.move.MoveConversionException: Coudn't parse destination square[dxe1R]: DXE1R
Exception: com.github.bhlangonijr.chesslib.move.MoveConversionException: Couldn't parse SAN to MoveList: Illegal move: g4f3 [gxf3+] on 8/p7/1b2B3/6k1/P2r1Pp1/8/6K1/5R2 b - f3 0 55
Exception: com.github.bhlangonijr.chesslib.move.MoveConversionException: Couldn't parse SAN to MoveList: Illegal move: f4g3 [fxg3] on 3r4/p4p1p/4b2P/2q2kpQ/2p2pP1/2N5/PPP5/2K4R b - g3 0 24

Could you please check this?

bhlangonijr commented 5 years ago

@alexmatv70 yes, we still had some bugs. It should be fixed now in version 1.1.5. Please validate.

Thank you, Ben

alexmatv70 commented 5 years ago

Version 1.1.5 is not available in repository yet. Please notify when ready.

alexmatv70 commented 5 years ago

Checked on version 1.1.5 The problem is still actual. I see lot of such exceptions trying to parse games from https://chess-db.com/public/downloads/gamesfordownload.jsp - Grandmasters' all games (both). Examples: com.github.bhlangonijr.chesslib.move.MoveConversionException: Couldn't parse SAN to MoveList: Illegal move: e8g8 [O-O] on 1Bb1k2r/4bpp1/2np3p/1R2p3/4P3/8/2PN1PPP/R5K1 b - - 0 26 com.github.bhlangonijr.chesslib.move.MoveConversionException: Couldn't parse SAN to MoveList: Illegal move: e1c1 [O-O-O] on r4rk1/3b1ppp/2p2q2/p1Ppn3/3Np3/2Q1P1P1/PP1N1P2/R3KR2 w - - 8 26

bhlangonijr commented 5 years ago

@alexmatv70 Thank you for pointing out this bug. This is something related to the state of castle rights during the process of the PGN file. If you process the games individually there are no errors but when you process the collection castle rights state is in error. I am fixing it and will do a new release.

bhlangonijr commented 5 years ago

Hi @alexmatv70 , this issue should be fixed in version 1.1.7

Although I found an invalid move in one game from the PGN you pointed me to: Move Kg2 in 46. Qb7+ Kg2 is not a valid one:

[Event "52^ Torneo Scacchistico Internazionale di Capodanno di Reggio Emilia"]
[Site "?"]
[Date "2010.01.05"]
[Round "1"]
[White "Vocaturo, Daniele"]
[Black "Brunello, Sabino"]
[Result "0-1"]
[PlyCount "0"]
[TimeControl "-"]
[ECO "B12"]
[WhiteElo "2526"]
[BlackElo "2533"]

1. e4 c6 2. d4 d5 3. e5 Bf5 4. Nf3 e6 5. Be2 Nd7 6. O-O Ne7 7. Nh4 Bg6 8. c3 c5 9. Nd2 cxd4 10. cxd4 Nc6 11. Nxg6 hxg6 12. Nf3 Be7 13. a3 g5 14. Qd3 Nf8 15. Be3 f6 16. b4 Kf7 17. Bd1 a5 18. b5 Nb8 19. Nd2 Ng6 20. f4 gxf4 21. Bxf4 Nxf4 22. Rxf4 Nd7 23. Bg4 Rh6 24. Nf3 f5 25. Bxf5 exf5 26. e6+ Rxe6 27. Qxf5+ Rf6 28. Qxd5+ Ke8 29. Re4 Rxf3 30. gxf3 Nf6 31. Qxb7 Nxe4 32. Qxe4 Rb8 33. a4 Rb6 34. Kh1 Kf7 35. Rc1 Rd6 36. Qf5+ Bf6 37. Rc8 Rd5 38. Qc2 Qd6 39. Qe4 Qd7 40. Qc2 Rxd4 41. Rc7 Rd1+ 42. Qxd1 Qxc7 43. Qb3+ Ke7 44. Qe3+ Kd7 45. Qe4 Qc5 46. Qb7+ Kg2 47. Ke7 Qc3 48. Qg6+ Kh1 49. Bb6 Qe5+ 50. Kf7 Qd5+ 51. Qe6 Qb7+ 52. Kf6 Kg2 53. Qe2+ Kh3 54. Qf1+ Kg3 55. Bf2+ Kg4 56. Qg2+ Kf4 57. Qg5+ Ke4

0-1
henkvo commented 5 years ago

Hi all, I have just tested the fix version 1.1.7 and the issue has been solved. Greets Henk

Van: Ben-Hur Carlos Vieira Langoni Junior notifications@github.com Verzonden: vrijdag 26 oktober 2018 01:33 Aan: bhlangonijr/chesslib chesslib@noreply.github.com CC: Subscribed subscribed@noreply.github.com Onderwerp: Re: [bhlangonijr/chesslib] Coudn't parse destination square[cxd8Q]: CXD8Q (#8)

Hi @alexmatv70https://github.com/alexmatv70 , this issue should be fixed in version 1.1.7

Although I found an invalid move in one game from the PGN you pointed me to: Move Kg2 in 46. Qb7+ Kg2 is not a valid one:

[Event "52^ Torneo Scacchistico Internazionale di Capodanno di Reggio Emilia"] [Site "?"] [Date "2010.01.05"] [Round "1"] [White "Vocaturo, Daniele"] [Black "Brunello, Sabino"] [Result "0-1"] [PlyCount "0"] [TimeControl "-"] [ECO "B12"] [WhiteElo "2526"] [BlackElo "2533"]

  1. e4 c6 2. d4 d5 3. e5 Bf5 4. Nf3 e6 5. Be2 Nd7 6. O-O Ne7 7. Nh4 Bg6 8. c3 c5 9. Nd2 cxd4 10. cxd4 Nc6 11. Nxg6 hxg6 12. Nf3 Be7 13. a3 g5 14. Qd3 Nf8 15. Be3 f6 16. b4 Kf7 17. Bd1 a5 18. b5 Nb8 19. Nd2 Ng6 20. f4 gxf4 21. Bxf4 Nxf4 22. Rxf4 Nd7 23. Bg4 Rh6 24. Nf3 f5 25. Bxf5 exf5 26. e6+ Rxe6 27. Qxf5+ Rf6 28. Qxd5+ Ke8 29. Re4 Rxf3 30. gxf3 Nf6 31. Qxb7 Nxe4 32. Qxe4 Rb8 33. a4 Rb6 34. Kh1 Kf7 35. Rc1 Rd6 36. Qf5+ Bf6 37. Rc8 Rd5 38. Qc2 Qd6 39. Qe4 Qd7 40. Qc2 Rxd4 41. Rc7 Rd1+ 42. Qxd1 Qxc7 43. Qb3+ Ke7 44. Qe3+ Kd7 45. Qe4 Qc5 46. Qb7+ Kg2 47. Ke7 Qc3 48. Qg6+ Kh1 49. Bb6 Qe5+ 50. Kf7 Qd5+ 51. Qe6 Qb7+ 52. Kf6 Kg2 53. Qe2+ Kh3 54. Qf1+ Kg3 55. Bf2+ Kg4 56. Qg2+ Kf4 57. Qg5+ Ke4

0-1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/bhlangonijr/chesslib/issues/8#issuecomment-433239231, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ALuW0p8nlM30PX7I364j43zKgfE02Rx5ks5uokofgaJpZM4XjeE4.

Disclaimer Dit bericht met eventuele bijlagen is vertrouwelijk en uitsluitend bestemd voor de geadresseerde. Indien u niet de bedoelde ontvanger bent, wordt u verzocht de afzender te waarschuwen en dit bericht met eventuele bijlagen direct te verwijderen en/of te vernietigen. Het is niet toegestaan dit bericht en eventuele bijlagen te vermenigvuldigen, door te sturen, openbaar te maken, op te slaan of op andere wijze te gebruiken. Ordina N.V. en/of haar groepsmaatschappijen accepteren geen verantwoordelijkheid of aansprakelijkheid voor schade die voortvloeit uit de inhoud en/of de verzending van dit bericht.

This e-mail and any attachments are confidential and are solely intended for the addressee. If you are not the intended recipient, please notify the sender and delete and/or destroy this message and any attachments immediately. It is prohibited to copy, to distribute, to disclose or to use this e-mail and any attachments in any other way. Ordina N.V. and/or its group companies do not accept any responsibility nor liability for any damage resulting from the content of and/or the transmission of this message.