pioz / chess

A fast chess library that use bitboards to play chess with Ruby
GNU Lesser General Public License v3.0
60 stars 17 forks source link

invalid FEN generation? #17

Closed mmcnl closed 6 years ago

mmcnl commented 6 years ago

Hello and thank you for this valuable library!

I believe I have found a case where an invalid FEN is generated. In the example below, after the move Qxh8, black is not legally able to castle (both black rooks are no longer in their original positions) and yet the generated FEN string indicates black can castle kingside: KQk.

> game = Chess::Game.load_fen("2b1kbnr/rpq1pp1p/2n3p1/8/3Q4/2P5/PP3PPP/RN2KBNR w KQk - 0 9")
=> #<Chess::Game:0x00007f85c9bcb910>

> puts game.board
8 . . b . k b n r
7 r p q . p p . p
6 . . n . . . p .
5 . . . . . . . .
4 . . . Q . . . .
3 . . P . . . . .
2 P P . . . P P P
1 R N . . K B N R
  a b c d e f g h
=> nil

> game.move('Qxh8')
=> "Qxh8"

> game.board.to_fen
=> "2b1kbnQ/rpq1pp1p/2n3p1/8/8/2P5/PP3PPP/RN2KBNR b KQk - 0 9"

> puts game.board
8 . . b . k b n Q
7 r p q . p p . p
6 . . n . . . p .
5 . . . . . . . .
4 . . . . . . . .
3 . . P . . . . .
2 P P . . . P P P
1 R N . . K B N R
  a b c d e f g h
pioz commented 6 years ago

@mmcnl thank you very much for reporting this bug! This commit should now fix the issue. Let me if now works!

mmcnl commented 6 years ago

Thank you for the quick response! The test cases in your code look great but I will verify it works for me as well.

mmcnl commented 6 years ago

Yes, works perfectly, thanks again!