diff --git a/chess/__init__.py b/chess/__init__.py index b74d710f..1509da86 100644 --- a/chess/__init__.py +++ b/chess/__init__.py @@ -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 diff --git a/test.py b/test.py index cc8a95b7..42fa0beb 100755 --- a/test.py +++ b/test.py @@ -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")