Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

fix(analyse): animate main-line clicks, drop arrow hints, |< returns to the played move

public

fix(analyse): animate main-line clicks, drop arrow hints, |< returns to the played move

- Clicking a main-line move in the move list goes through _analysis_open_node and
  animates the move, like a click on a variation move.
- The info box no longer explains forks ("Weiter mit >: … Oder Pfeil anklicken: …");
  labelled arrows and the move list are enough.
- When replaying, |< has no present to return to: it is hidden on the main line and
  inside a variation jumps back to the played move the variation replaces.

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

modified schach/app.py +2 −1

@@ -1774,7 +1774,8 @@ class Window(OnlineMixin, PuzzleMixin, O
17741774
         if ply >= last and self.mode != "review" and not self._over():
17751775
             self._end_browse()  # der letzte Zug einer laufenden Partie: zurück ins Spiel
17761776
             return
1777
-        self._analysis_open(min(ply, last))  # nach der Partie: Nachspielen (siehe _analysis_open)
1777
+        self._analysis_open_node(self._game_node(min(ply, last)))  # nach der Partie: Nachspielen
1778
+        # (über _analysis_open_node, damit der Zug wie bei einem Variantenzug animiert wird)
17781779
 
17791780
     def _movelist_update(self):
17801781
         """Zugliste samt Nebenvarianten vom Analysebrett; markiert, wo das Analysebrett gerade steht."""

modified schach/training.py +27 −15

@@ -271,7 +271,7 @@ class OpeningMixin:
271271
         # Vorführung: die Gegenwart liegt links (|<), die gedachte Zukunft rechts davon
272272
         self.coach_first = Gtk.Button(icon_name="go-first-symbolic", tooltip_text="Zurück zur Partie (Esc)",
273273
                                       css_classes=["flat"], visible=False)
274
-        self.coach_first.connect("clicked", lambda *_: self._demo_end())
274
+        self.coach_first.connect("clicked", lambda *_: self._coach_first())
275275
         self.coach_nav.append(self.coach_first)
276276
         self.coach_prev = Gtk.Button(icon_name="go-previous-symbolic", tooltip_text="Vorherige Rückmeldung",
277277
                                      css_classes=["flat"])
@@ -552,6 +552,24 @@ class OpeningMixin:
552552
         self._refresh()
553553
         self._coach_show()
554554
 
555
+    def _main_line_return(self, node):
556
+        """Der gespielte Zug, den die Nebenvariante mit ``node`` ersetzt (None auf der Hauptlinie)."""
557
+        tree, first = self.demo["tree"], None
558
+        while node.parent is not None and not tree.meta.get(node, {}).get("played"):
559
+            node, first = node.parent, node
560
+        if first is None:
561
+            return None
562
+        return next((c for c in node.variations if tree.meta.get(c, {}).get("played")), node)
563
+
564
+    def _coach_first(self):
565
+        """|<: beim Nachspielen zurück auf die Hauptlinie, sonst zurück zur Partie."""
566
+        if self.demo is not None and self.demo.get("game") and self.replaying:
567
+            target = self._main_line_return(self.demo["node"])
568
+            if target is not None and not self.demo["busy"]:
569
+                self._analysis_open_node(target)
570
+            return
571
+        self._demo_end()
572
+
555573
     def _demo_end(self):
556574
         if self.demo is None:
557575
             return False
@@ -1015,17 +1033,8 @@ class OpeningMixin:
10151033
             if self.demo.get("game") and not busy else None
10161034
         if best is not None and best.comment:  # „Warum nicht?“: die Begründung schon an der Gabelung
10171035
             markup += "\n" + _escape(notation.text(best.comment, style))
1018
-        if len(node.variations) > 1 and not busy:
1019
-            board = node.board()
1020
-            ahead = self._demo_next(node)
1021
-            others = [c for c in node.variations if c is not ahead]
1022
-
1023
-            def option(child):
1024
-                name = tree.label(child)
1025
-                return _escape(notation.move(board, child.move, style)) + (f" ({_escape(name)})" if name else "")
1026
-            markup += (f"\n<span alpha='70%'>Weiter mit &gt;: {option(ahead)}. Oder Pfeil anklicken: "
1027
-                       + ", ".join(option(c) for c in others) + ".</span>")
1028
-        elif not busy and (suggested := explain.suggestions(tree, node)):
1036
+        # Gabelungen erklären sich über die Pfeile mit Schild und die Zugliste selbst (24.11.2026)
1037
+        if len(node.variations) <= 1 and not busy and (suggested := explain.suggestions(tree, node)):
10291038
             board = node.board()
10301039
             words = [_escape(notation.move(board, move, style)) + (f" ({_escape(label)})" if label else "")
10311040
                      for move, label in suggested]
@@ -1037,11 +1046,14 @@ class OpeningMixin:
10371046
         self.coach_prev.set_sensitive(depth > 0 and not busy)
10381047
         self.coach_next.set_sensitive(bool(node.variations) and not busy)
10391048
         self.coach_last.set_visible(False)
1040
-        self.coach_first.set_visible(True)
10411049
         if self.demo.get("game") and self.replaying:
1042
-            self.coach_first.set_tooltip_text("Nachspielen beenden (Esc)")
1043
-            self.coach_first.set_sensitive(not busy and self.recorder is None)
1050
+            # Nachspielen hat keine Gegenwart, zu der |< zurückführt: nur in einer Nebenvariante
1051
+            # zurück zum gespielten Zug, den sie ersetzt (Esc beendet das Nachspielen weiterhin)
1052
+            self.coach_first.set_visible(self._main_line_return(node) is not None)
1053
+            self.coach_first.set_tooltip_text("Zurück zum gespielten Zug")
1054
+            self.coach_first.set_sensitive(not busy)
10441055
         else:
1056
+            self.coach_first.set_visible(True)
10451057
             self.coach_first.set_tooltip_text("Zurück zur Partie (Esc)")
10461058
             self.coach_first.set_sensitive(True)
10471059
         self.coach_trace.set_visible(True)

added tests/test_nachspielen_nav.py +52 −0

@@ -0,0 +1,52 @@
1
+"""Nachspielen: Klick auf einen Zug der Hauptlinie animiert ihn wie ein Variantenzug, und |< führt aus
2
+einer Nebenvariante zurück zum gespielten Zug, den sie ersetzt. Nutzerbericht 24.11.2026."""
3
+
4
+import types
5
+import unittest
6
+
7
+import chess
8
+
9
+from schach import app
10
+from tests.test_zustand_regression import FakeWindow, played
11
+
12
+
13
+class Window(FakeWindow):
14
+    _browse = app.Window._browse
15
+
16
+    def __init__(self, board, mode="review"):
17
+        super().__init__(board, mode)
18
+        self.animated = []
19
+        self.view = types.SimpleNamespace(animate_move=lambda board, move: self.animated.append(move))
20
+
21
+    def _end_browse(self):
22
+        raise AssertionError("nicht erwartet")
23
+
24
+
25
+class NavTest(unittest.TestCase):
26
+    def setUp(self):
27
+        self.win = Window(played("e4", "e5", "Nf3", "Nc6"))
28
+        self.win._game_tree()
29
+
30
+    def test_klick_auf_hauptzug_animiert(self):
31
+        win = self.win
32
+        win._browse(2)
33
+        self.assertEqual(win.animated, [chess.Move.from_uci("g1f3")])
34
+        self.assertEqual(win.demo["node"].move, chess.Move.from_uci("g1f3"))
35
+        self.assertTrue(win.replaying)
36
+
37
+    def test_erster_knopf_nur_in_nebenvariante(self):
38
+        win = self.win
39
+        win._browse(2)
40
+        self.assertIsNone(win._main_line_return(win.demo["node"]))  # Hauptlinie: |< verschwindet
41
+        side = win._game_node(1).add_variation(chess.Move.from_uci("f1c4"))  # statt 2. Sf3
42
+        deep = side.add_variation(chess.Move.from_uci("g8f6"))
43
+        win._analysis_open_node(deep)
44
+        played_move = win._game_node(2)
45
+        self.assertIs(win._main_line_return(deep), played_move)
46
+        win._coach_first()
47
+        self.assertIs(win.demo["node"], played_move)
48
+        self.assertTrue(win.replaying)  # bleibt im Nachspielen
49
+
50
+
51
+if __name__ == "__main__":
52
+    unittest.main()