bhlangonijr / chesslib

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

San generation for castling checkmate move #47

Closed dlbbld closed 3 years ago

dlbbld commented 3 years ago

You are overlooking that castle can cause check or checkmate. The SAN for the move O-O-O# is wrongly generated as O-O-O.

final String san = "1. d4 e6 2. Nf3 f5 3. Nc3 Nf6 4. Bg5 Be7 5. Bxf6 Bxf6 6. e4 fxe4 7. Nxe4 b6 "
    + "8. Ne5 O-O 9. Bd3 Bb7 10. Qh5 Qe7 11. Qxh7+ Kxh7 12. Nxf6+ Kh6 13. Neg4+ Kg5 14. h4+ Kf4 "
    + "15. g3+ Kf3 16. Be2+ Kg2 17. Rh2+ Kg1 18. O-O-O#";

final MoveList moveList = new MoveList();
moveList.loadFromSan(san);
final String sanGeneratedLastMove = moveList.toSanArray()[moveList.toSanArray().length - 1]; 
assertEquals("O-O-O#", sanGeneratedLastMove); // expected O-O-O# but O-O-O is generated

From famous game where last move was 18. Kd2# but could have been 18. O-O-O#.

bhlangonijr commented 3 years ago

Fixed in version 1.2.2

dlbbld commented 3 years ago

This looks ok.