diff --git a/CHANGELOG.rst b/CHANGELOG.rst index b85580ca9..02418c615 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,12 @@ is more important to get things right, than to be consistent with previous versions. Use this changelog to see what changed in a new release, because this might include API breaking changes. +New in v0.4.2 +------------- + +* Fix bug where `pawn_moves_from()` and consequently `is_legal()` weren't + handling en-passant correctly. Thanks to Norbert Naskov for reporting. + New in v0.4.1 ------------- diff --git a/chess/__init__.py b/chess/__init__.py index 46da0bc1b..5720e46c2 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -20,7 +20,7 @@ __email__ = "niklas.fiekas@tu-clausthal.de" -__version__ = "0.4.1" +__version__ = "0.4.2" import collections import re @@ -1374,7 +1374,7 @@ def pawn_moves_from(self, square): if not self.ep_square: targets |= BB_PAWN_ATTACKS[self.turn][square] & self.occupied_co[self.turn ^ 1] else: - targets |= BB_PAWN_ATTACKS[self.turn][square] & (self.occupied_co[self.turn ^ 1] | BB_SQUARES[square]) + targets |= BB_PAWN_ATTACKS[self.turn][square] & (self.occupied_co[self.turn ^ 1] | BB_SQUARES[self.ep_square]) return targets diff --git a/test.py b/test.py index ca1f309c5..63d067d03 100755 --- a/test.py +++ b/test.py @@ -660,6 +660,13 @@ def test_fifty_moves(self): self.assertFalse(board.can_claim_fifty_moves()) self.assertFalse(board.can_claim_draw()) + def test_ep_legality(self): + board = chess.Bitboard("rnbqkbnr/pppppp2/7p/6pP/8/8/PPPPPPP1/RNBQKBNR w KQkq g6 0 3") + self.assertTrue(board.is_legal(chess.Move.from_uci("h5g6"))) + board.push_san("Nf3") + board.push_san("Nf6") + self.assertFalse(board.is_legal(chess.Move.from_uci("h5g6"))) + class LegalMoveGeneratorTestCase(unittest.TestCase):