Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions chess/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2297,14 +2297,11 @@ def can_claim_fifty_moves(self) -> bool:
return True

if self.halfmove_clock >= 99:
# The claim can also be made ahead of a move that would itself give
# checkmate or stalemate (FIDE 9.3): it is declared, not played.
for move in self.generate_legal_moves():
if not self.is_zeroing(move):
self.push(move)
try:
if self.is_fifty_moves():
return True
finally:
self.pop()
return True

return False

Expand Down
9 changes: 9 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,15 @@ def test_fifty_moves(self):
self.assertFalse(board.can_claim_fifty_moves())
self.assertFalse(board.can_claim_draw())

# Claiming ahead of a move that would itself give checkmate is valid
# (FIDE 9.3): the move is only declared, not played.
board = chess.Board("6rk/6pp/7N/5p2/6p1/8/2q5/K7 w - - 99 60")
self.assertFalse(board.is_game_over())
self.assertTrue(board.gives_checkmate(chess.Move.from_uci("h6f7")))
self.assertFalse(board.is_fifty_moves())
self.assertTrue(board.can_claim_fifty_moves())
self.assertTrue(board.can_claim_draw())

def test_promoted_comparison(self):
board = chess.Board()
board.set_fen("5R2/3P4/8/8/7r/7r/7k/K7 w - - 0 1")
Expand Down
Loading