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
2 changes: 1 addition & 1 deletion chess/pgn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]"]
Expand Down
Loading