Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

fix(review): the timeline waits while an own move is being analysed

public

fix(review): the timeline waits while an own move is being analysed

While the engine was answering a move made on the analysis board, a
playback step (e.g. after Space) moved the board to another node, and the
pending move was then pushed onto a position where it is illegal. The strip
of captured pieces showed None and drawing raised. _playback_apply now waits
until the move is in; the strip skips such entries instead of crashing.
Regression tests for both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Changeset12e981706f992b073a2aa3efab32d800958ed0af
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parents251f018b8a06
Children10b46625c441
Pushlog
by timo via ssh
by timo via ssh

modified schach/diagram.py +3 −1

@@ -245,7 +245,9 @@ class BoardPainter:
245245
                 if replay.is_en_passant(move):
246246
                     result[replay.turn].append(chess.Piece(chess.PAWN, not replay.turn))
247247
                 elif replay.is_capture(move) and not replay.is_castling(move):
248
-                    result[replay.turn].append(replay.piece_at(move.to_square))
248
+                    piece = replay.piece_at(move.to_square)
249
+                    if piece is not None:  # Zug passt nicht zur Stellung (push prüft nicht): nicht abstürzen
250
+                        result[replay.turn].append(piece)
249251
                 replay.push(move)
250252
             self._captures_key, self._captures = key, result
251253
         captured = {c: list(p) for c, p in self._captures.items()}

modified schach/review.py +2 −0

@@ -419,6 +419,8 @@ class ReviewMixin:
419419
         shown = recording.at(self.playback["frames"], self._playback_ms())
420420
         if shown == self.playback["shown"] and not force:
421421
             return
422
+        if self.demo is not None and self.demo.get("busy"):
423
+            return  # selbst gezogener Zug wird noch berechnet; danach holt der nächste Takt das nach
422424
         self.playback["shown"] = shown
423425
         path, shapes = shown
424426
         node = self.game_tree.game if self.game_tree is not None else None

modified tests/test_drawing.py +15 −0

@@ -40,3 +40,18 @@ class ToggleTest(unittest.TestCase):
4040
 
4141
 if __name__ == "__main__":
4242
     unittest.main()
43
+
44
+
45
+class CapturesTest(unittest.TestCase):
46
+    def test_history_that_does_not_fit_the_start_does_not_crash(self):
47
+        """Gefunden am 24.11.2026 vom Zufallstest (seltene Ausnahme beim Zeichnen): steht ein Zug
48
+        auf dem Brett, der dort nicht legal ist (push prüft das nicht), meldet python-chess einen
49
+        Schlagzug auf ein leeres Feld; im Streifen stand dann None. Ursache: siehe
50
+        test_zustand_regression.BusyTest."""
51
+        from schach import diagram
52
+
53
+        board = chess.Board()
54
+        board.push_san("e4")
55
+        board.push(chess.Move(chess.E4, chess.E5))  # push prüft nicht: Weiß zieht, obwohl Schwarz dran ist
56
+        captured = diagram.Diagram(board)._captured_by()
57
+        self.assertNotIn(None, captured[chess.WHITE] + captured[chess.BLACK])

modified tests/test_zustand_regression.py +24 −0

@@ -31,6 +31,12 @@ class _Media:
3131
     def get_playing(self):
3232
         return self.playing
3333
 
34
+    def get_ended(self):
35
+        return False
36
+
37
+    def get_timestamp(self):
38
+        return 0
39
+
3440
 
3541
 class _Revealer:
3642
     def __init__(self):
@@ -176,5 +182,23 @@ class GeschlossenTest(unittest.TestCase)
176182
             method(closed)  # darf nichts anfassen
177183
 
178184
 
185
+class BusyTest(unittest.TestCase):
186
+    def test_zeitleiste_wartet_auf_den_selbst_gezogenen_zug(self):
187
+        """Gefunden am 24.11.2026 (Ursache des seltenen None im Streifen der geschlagenen Figuren):
188
+        Während die Engine einen selbst gezogenen Zug auf dem Analysebrett berechnet („busy“),
189
+        setzte _playback_apply (etwa nach der Leertaste) das Brett auf einen anderen Knoten.
190
+        _demo_refresh legte den Zug dann auf eine Stellung, in der er gar nicht legal ist."""
191
+        win = FakeWindow(played("e4", "e5"), mode="review")
192
+        win.start_playback()
193
+        before = win.demo["node"]
194
+        win.demo["busy"] = chess.Move.from_uci("g1f3")  # gerade selbst gezogen, Antwort kommt noch
195
+        win.playback["frames"] = [(0, (chess.Move.from_uci("e2e4"),), ())]  # Zeitleiste: nach 1. e4
196
+        win._playback_apply(force=True)
197
+        self.assertIs(win.demo["node"], before)
198
+        win.demo["busy"] = False  # Antwort ist da: jetzt darf die Zeitleiste wieder
199
+        win._playback_apply(force=True)
200
+        self.assertEqual(win.demo["node"].move, chess.Move.from_uci("e2e4"))
201
+
202
+
179203
 if __name__ == "__main__":
180204
     unittest.main()