Skip to content

Commit

Permalink
Fix en-passant bug in Bitboard.pawn_moves_from()
Browse files Browse the repository at this point in the history
  • Loading branch information
niklasf committed Oct 10, 2014
1 parent 5b61d68 commit 4d8bb83
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-------------

Expand Down
4 changes: 2 additions & 2 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

__email__ = "niklas.fiekas@tu-clausthal.de"

__version__ = "0.4.1"
__version__ = "0.4.2"

import collections
import re
Expand Down Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down

0 comments on commit 4d8bb83

Please sign in to comment.