From 1fbbbb6bcc14f4ec986116544de5546c46ed5c35 Mon Sep 17 00:00:00 2001 From: kwy404 Date: Sat, 26 Sep 2026 02:46:30 -0300 Subject: [PATCH] Fix GameNode.set_eval() dropping mate 0 scores set_eval() only wrote a mate annotation when score.white().mate() was truthy, so Mate(0) and MateGiven were silently discarded, and an existing [%eval ...] annotation was removed instead of being replaced by [%eval #0]. GameNode.eval() already parses [%eval #0], so writing back the parsed score lost it. --- chess/pgn.py | 2 +- test.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/chess/pgn.py b/chess/pgn.py index 3d4d7e5ff..627f3fd84 100644 --- a/chess/pgn.py +++ b/chess/pgn.py @@ -497,7 +497,7 @@ def set_eval(self, score: Optional[chess.engine.PovScore], depth: Optional[int] cp = score.white().score() if cp is not None: eval = f"[%eval {float(cp) / 100:.2f}{depth_suffix}]" - elif score.white().mate(): + elif score.white().mate() is not None: eval = f"[%eval #{score.white().mate()}{depth_suffix}]" self._replace_or_add_annotation(eval, EVAL_REGEX) diff --git a/test.py b/test.py index a481c2adb..0ec62b8ae 100755 --- a/test.py +++ b/test.py @@ -2957,6 +2957,13 @@ def test_eval(self): game.set_eval(chess.engine.PovScore(chess.engine.Cp(cp), chess.WHITE)) self.assertEqual(game.eval().white().cp, cp) + def test_eval_mate_zero(self): + game = chess.pgn.read_game(io.StringIO("1. f3 e5 2. g4 Qh4# { [%eval #0] } 0-1")) + node = game.end() + node.set_eval(node.eval()) + self.assertEqual(node.comments, ["[%eval #0]"]) + self.assertEqual(node.eval().relative, chess.engine.Mate(0)) + def test_float_emt(self): game = chess.pgn.Game() game.comments = ["[%emt 0:00:01.234]"]