feat(replay): end screen, replay mode, move-only variations
public
feat(replay): end screen, replay mode, move-only variations - end screen keeps final position; replay opens on demand (sidebar too), finished/foreign games open in replay - replay: only the player moves; replies become clickable suggestion arrows (Maia oft/selten) instead of auto-moves - move list: one move per row with eval bars, "Variante n" level for multiple or named branches (PGN starting comment) - defer list selection handling: rebuilding the list inside GTK's row signal segfaulted - rename Analysebrett to Nachspielen, save name with year
| Changeset | b5a695421283101f529fdacc646895902a557663 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 82b1120eb5ae |
| Children | 613dd40fd127 |
| Pushlog | by timo via ssh by timo via ssh |
modified ROADMAP.md +1 −1
| @@ -634,7 +634,7 @@ behält Reihenfolge und offene Fragen. | ||
| 634 | 634 | | Datei | Inhalt | Status | |
| 635 | 635 | | --- | --- | --- | |
| 636 | 636 | | [`roadmap/analysebrett.md`](roadmap/analysebrett.md) | Analysebrett mit Variantenbaum, „Warum?“ und „Warum nicht?“ | Stufen 1–4 umgesetzt | |
| 637 | -| [`roadmap/nachbesprechung.md`](roadmap/nachbesprechung.md) | Pfeile zeichnen, Zugliste als Baum, Partie vertont durchgehen (Aufnahme, Wiedergabe) | Stufen 1–2 umgesetzt | | |
| 637 | +| [`roadmap/nachbesprechung.md`](roadmap/nachbesprechung.md) | Pfeile zeichnen, Zugliste als Baum, Schlussbild und Nachspielen, Partie vertont durchgehen (Aufnahme, Wiedergabe) | Stufen 1–2a umgesetzt | | |
| 638 | 638 | | [`roadmap/training.md`](roadmap/training.md) | Rätsel aus eigenen Partien, „Aus Fehlern lernen“, Wiederholung mit FSRS und SQLite | Schritte 1 und 2 umgesetzt, zurückgenommene Züge im PGN | |
| 639 | 639 | |
| 640 | 640 | ## Reihenfolge |
modified roadmap/nachbesprechung.md +35 −4
| @@ -21,16 +21,47 @@ alles weg. | ||
| 21 | 21 | |
| 22 | 22 | ## 2. Zugliste als Baum (umgesetzt) |
| 23 | 23 | |
| 24 | -Die Partie läuft Zeile für Zeile nach unten. Ein Zug mit Nebenvarianten hat einen | |
| 25 | -Aufklapp-Pfeil, darunter stehen die Varianten. Jeder Zug darin ist anklickbar, Alternativen | |
| 26 | -innerhalb einer Variante hängen eine Stufe tiefer und lassen sich ebenso aufklappen. Steht | |
| 27 | -das Analysebrett in einer Variante, klappt die Liste bis dorthin auf und markiert den Zug. | |
| 24 | +Die Partie läuft Zeile für Zeile nach unten, Varianten ebenso: ein Zug pro Zeile, mit | |
| 25 | +Gewinnchance-Balken (Stockfish rechnet sie für Variantenzüge nach). Zweigt an einem Zug genau | |
| 26 | +eine Variante ab, klappt der Zug sie direkt auf. Bei mehreren steht dazwischen eine Ebene mit | |
| 27 | +kursiven Kopfzeilen „Variante 1“, „Variante 2“ … (mit dem ersten Zug daneben), die man einzeln | |
| 28 | +aufklappt. Hat eine Variante im PGN einen Namen (Kommentar vor dem ersten Zug, | |
| 29 | +`( { Name } 10. Lxf7+ … )`), steht er in der Kopfzeile; dann gibt es die Kopfzeile auch bei nur | |
| 30 | +einer Variante. Steht das Brett in einer Variante, klappt die Liste bis dorthin auf. | |
| 28 | 31 | |
| 29 | 32 | Tastatur wie bei Bäumen üblich (WAI-ARIA Treeview): ↑/↓ durch die sichtbaren Zeilen, bei |
| 30 | 33 | zugeklappten Zweigen also nur durch die Partie. → klappt auf bzw. geht in die erste |
| 31 | 34 | Variante, ← klappt zu bzw. zurück zur Zeile darüber. Gibt es nichts auf- oder zuzuklappen, |
| 32 | 35 | gehen ← und → wie bisher ans Brett. |
| 33 | 36 | |
| 37 | +## 2a. Schlussbild und Nachspielen (umgesetzt) | |
| 38 | + | |
| 39 | +Nach der Partie bleibt die Endstellung stehen, als Schlussbild. Die graue Leiste zeigt das | |
| 40 | +Ergebnis mit „Nachspielen“ und „Neue Partie“, die Seitenleiste bleibt zu. Das gilt für | |
| 41 | +Partien gegen Maia, Online-Partien und Partien zu zweit, auch wenn man eine eigene Partie | |
| 42 | +später wieder öffnet. | |
| 43 | + | |
| 44 | +- „Nachspielen“ klappt die Zugliste auf und startet an der Ausgangsstellung, das Brett | |
| 45 | + durchgehend in den Nachspielfarben (getönt). Die Leiste zeigt „Nachspielen · Ergebnis“ und „Ab hier weiterspielen“ | |
| 46 | + (gegen Maia ab der gezeigten Stellung, in einem neuen Fenster). | |
| 47 | +- ← und ein Klick in die Zugliste sind Abkürzungen dafür. Esc führt zurück zum Schlussbild. | |
| 48 | +- Geöffnete Partien, die schon zu Ende sind, und fremde Partien öffnen gleich im | |
| 49 | + Nachspielen. Das Schlussbild gibt es direkt nach dem Spielen (und mit Esc). | |
| 50 | +- Beim Nachspielen zieht nur man selbst. Nach einem eigenen Zug kommt nur dieser in den Baum, | |
| 51 | + mit Kommentar („Besser war …“). Mögliche Antworten stehen als anklickbare Pfeile daneben | |
| 52 | + („Maia oft“, „Maia selten“, „Bester Zug“); erst der Klick hängt den Zug ein. | |
| 53 | +- Geplant: dritter Knopf „Nachbesprechen“ im Schlussbild (Nachbesprechen · Nachspielen · | |
| 54 | + Neue Partie): Nachspielen mit laufender Aufnahme. | |
| 55 | +- Die Zugzeichen rechnet Stockfish trotzdem gleich nach dem Ende aus, im Hintergrund. | |
| 56 | +- Die Leiste ist eine eigene (`schach/endbar.py`) im Aussehen von `Adw.Banner`, weil | |
| 57 | + `Adw.Banner` nur einen Knopf kann. | |
| 58 | + | |
| 59 | +## Idee: Hinweis und Bedrohung als Nachspielen | |
| 60 | + | |
| 61 | +Hinweis (H), Bedrohung (B), „Warum?“ und „Warum nicht?“ zeigen heute je eigene Pfeile und Texte. | |
| 62 | +Einheitlicher wäre: Alle erzeugen einen kommentierten Variantenbaum (PGN) und zeigen ihn im | |
| 63 | +Nachspielen, mit denselben Pfeilen, Kommentaren und Vorschlägen. Noch nicht begonnen. | |
| 64 | + | |
| 34 | 65 | ## 3. Aufnahme (offen) |
| 35 | 66 | |
| 36 | 67 | Kein Bildschirmvideo, sondern Ton plus Zeitleiste: Während der Aufnahme schreibt die App |
modified schach/app.py +66 −39
| @@ -15,14 +15,15 @@ gi.require_version("Gtk", "4.0") | ||
| 15 | 15 | gi.require_version("Adw", "1") |
| 16 | 16 | from gi.repository import Adw, Gdk, Gio, GLib, GObject, Gtk # noqa: E402 |
| 17 | 17 | |
| 18 | -from . import annotate, clipboard, energy, lichess, notation, savegames # noqa: E402 | |
| 18 | +from . import annotate, clipboard, energy, explain, lichess, notation, savegames # noqa: E402 | |
| 19 | 19 | from .repetition import DEFAULT_RETENTION # noqa: E402 |
| 20 | 20 | from .board import BoardView, available_themes # noqa: E402 |
| 21 | +from .endbar import EndBar # noqa: E402 | |
| 21 | 22 | from .movelist import MoveList # noqa: E402 |
| 22 | 23 | from .prefs import Preferences # noqa: E402 |
| 23 | 24 | from .engines import MAIA_CMD, MAIA_CWD, MAIA_PREPARE, STOCKFISH_CMD, EngineWorker, maia_candidates, maia_move, maia_probabilities # noqa: E402 |
| 24 | 25 | from .threat import null_board, threat_job # noqa: E402 |
| 25 | -from .explain import explain_job, explore_job, graft, why_not_job # noqa: E402 | |
| 26 | +from .explain import explain_job, explore_job, graft_move, why_not_job # noqa: E402 | |
| 26 | 27 | from .online import OnlineMixin # noqa: E402 |
| 27 | 28 | from .puzzles import PuzzleMixin # noqa: E402 |
| 28 | 29 | from .training import OpeningMixin, set_book_paths, set_retention # noqa: E402 |
| @@ -58,8 +59,8 @@ SHORTCUTS = [ | ||
| 58 | 59 | ]), |
| 59 | 60 | ("Ansicht", [ |
| 60 | 61 | ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"), |
| 61 | - ("Analysebrett: einen Zug zurück / vor", "Left Right"), | |
| 62 | - ("Zurück zur aktuellen Stellung, Hinweis ausblenden", "Escape"), | |
| 62 | + ("Nachspielen: einen Zug zurück / vor", "Left Right"), | |
| 63 | + ("Nachspielen beenden, Hinweis ausblenden", "Escape"), | |
| 63 | 64 | ]), |
| 64 | 65 | ("Spielstände", [ |
| 65 | 66 | ("Spielstand speichern", "<Control>s"), ("Spielstände öffnen", "<Control>o"), |
| @@ -168,6 +169,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 168 | 169 | self.key_ply = {} # FEN -> Halbzug-Index der Stellung |
| 169 | 170 | self.browse_ply = None # in der Zugliste gewählte Stellung (nur Ansicht) |
| 170 | 171 | self.end_shown = False |
| 172 | + self.replaying = False # „Nachspielen“: fertige Partie auf dem Analysebrett (sonst Schlussbild) | |
| 171 | 173 | self.mode = "maia" |
| 172 | 174 | self.opponent = "" # Gegnername, wenn nicht Maia |
| 173 | 175 | self.names = () # (Weiß, Schwarz) bei fremden Partien |
| @@ -245,7 +247,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 245 | 247 | self.lichess_section = Gio.Menu() |
| 246 | 248 | menu.append_section("Lichess", self.lichess_section) |
| 247 | 249 | view = Gio.Menu() |
| 248 | - view.append("_Analysebrett", "win.analysis") | |
| 250 | + view.append("_Nachspielen", "win.analysis") | |
| 249 | 251 | view.append("Brett _drehen", "win.flip") |
| 250 | 252 | menu.append_section(None, view) |
| 251 | 253 | about = Gio.Menu() |
| @@ -313,8 +315,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 313 | 315 | self.bottom_bar = Gtk.ActionBar() |
| 314 | 316 | self.narrow = False |
| 315 | 317 | |
| 316 | - self.banner = Adw.Banner(button_label="Neue Partie") | |
| 317 | - self.banner.set_action_name("win.new-game") | |
| 318 | + self.banner = EndBar() # wie Adw.Banner, aber mit mehreren Knöpfen (Nachspielen, Neue Partie) | |
| 318 | 319 | |
| 319 | 320 | self.view = BoardView(theme=self.settings["theme"], scheme=self.settings["scheme"]) |
| 320 | 321 | self.view.on_move = self._on_board_move |
| @@ -404,6 +405,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 404 | 405 | ("open-saves", self._saves_dialog), |
| 405 | 406 | ("end-browse", self._end_browse), |
| 406 | 407 | ("analysis", lambda *_: self._analysis_open(len(self.board.move_stack) - 1)), |
| 408 | + ("replay", lambda *_: self._replay_start()), | |
| 409 | + ("replay-continue", lambda *_: self._replay_continue()), | |
| 407 | 410 | ("toggle-list", lambda *_: self.list_btn.set_active(not self.list_btn.get_active())), |
| 408 | 411 | ("puzzle", self._puzzle_action), |
| 409 | 412 | ("lichess-login", lambda *_: self.get_application().lichess_login(self)), |
| @@ -540,6 +543,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 540 | 543 | self._truncate_extras(0) |
| 541 | 544 | self.review_requested = set() |
| 542 | 545 | self.end_shown = False |
| 546 | + self.replaying = False | |
| 543 | 547 | self.badge_ply = None |
| 544 | 548 | self.maia_thinking = False |
| 545 | 549 | self.view.selected = None |
| @@ -565,8 +569,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 565 | 569 | if self.mode == "setup": |
| 566 | 570 | self._setup_refresh() |
| 567 | 571 | return |
| 568 | - if self.demo is None and self.mode == "review" and self._analysis_allowed(): | |
| 569 | - self._analysis_open(len(self.board.move_stack) - 1, show=False) # fertige Partie: Analysebrett | |
| 572 | + if self.demo is None and self.replaying and self._analysis_allowed(): | |
| 573 | + self._analysis_open(len(self.board.move_stack) - 1, show=False) # Nachspielen: Analysebrett bleibt | |
| 570 | 574 | self._coach_show() |
| 571 | 575 | if self.demo is not None: |
| 572 | 576 | self._demo_refresh() |
| @@ -658,9 +662,9 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 658 | 662 | extra = f" · {start}" if start else "" |
| 659 | 663 | self.title.set_subtitle(f"gegen {self.opponent} · {tc} · {rated}{extra}") |
| 660 | 664 | elif self.mode == "review" and self.names: |
| 661 | - self.title.set_subtitle("Analyse") | |
| 665 | + self.title.set_subtitle("Nachspielen") | |
| 662 | 666 | elif self.mode == "review": |
| 663 | - self.title.set_subtitle(f"gegen {self.opponent} · du warst {side}" if self.opponent else "Analyse") | |
| 667 | + self.title.set_subtitle(f"gegen {self.opponent} · du warst {side}" if self.opponent else "Nachspielen") | |
| 664 | 668 | elif not self.maia_ready: |
| 665 | 669 | self.title.set_subtitle(self.get_application().maia_status) |
| 666 | 670 | else: |
| @@ -750,29 +754,26 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 750 | 754 | p = self.puzzle |
| 751 | 755 | if text and p and p["rating_diff"] is not None: |
| 752 | 756 | text = f"{text} Deine Rätselwertung: {p['rating_diff']:+d}" |
| 753 | - self.banner.set_button_label("Nächstes Rätsel") | |
| 754 | - self.banner.set_action_name("win.puzzle") | |
| 757 | + buttons = [("Nächstes Rätsel", "win.puzzle")] | |
| 755 | 758 | elif self.mode == "opening": |
| 756 | - self.banner.set_button_label("Nächste Linie") | |
| 757 | - self.banner.set_action_name("win.opening-next") | |
| 758 | - else: | |
| 759 | - self.banner.set_button_label("Neue Partie") | |
| 760 | - self.banner.set_action_name("win.new-game") | |
| 759 | + buttons = [("Nächste Linie", "win.opening-next")] | |
| 760 | + elif self.replaying: | |
| 761 | + buttons = [("Ab hier _weiterspielen", "win.replay-continue")] | |
| 762 | + text = "Nachspielen" + (f" · {text}" if text else "") | |
| 763 | + else: # Schlussbild: erst auf Wunsch nachspielen | |
| 764 | + buttons = [("Nach_spielen", "win.replay")] if self._analysis_allowed() else [] | |
| 765 | + buttons.append(("_Neue Partie", "win.new-game")) | |
| 761 | 766 | banner = text |
| 762 | 767 | if text is None and self.mode == "online" and self.online_offline: |
| 763 | 768 | # dauerhafter Zustand, kein Ereignis: Banner statt Toast (HIG) |
| 764 | 769 | banner = "Verbindung zu Lichess unterbrochen – die Partie und deine Uhr laufen weiter" |
| 765 | - self.banner.set_button_label("") | |
| 770 | + buttons = [] | |
| 766 | 771 | elif text is None and self.mode in ("online", "puzzle") and self.get_application().lichess_expired: |
| 767 | 772 | banner = "Lichess-Anmeldung abgelaufen" |
| 768 | - self.banner.set_button_label("Neu anmelden") | |
| 769 | - self.banner.set_action_name("win.lichess-login") | |
| 770 | - self.banner.set_title(banner or "") | |
| 771 | - self.banner.set_revealed(banner is not None) | |
| 773 | + buttons = [("Neu anmelden", "win.lichess-login")] | |
| 774 | + self.banner.show(banner, buttons) | |
| 772 | 775 | if text and not self.end_shown: |
| 773 | - self.end_shown = True | |
| 774 | - if self.mode not in ("puzzle", "opening"): | |
| 775 | - self.list_btn.set_active(True) # Partie vorbei: Analyse aufklappen | |
| 776 | + self.end_shown = True # Seitenleiste bleibt zu: Schlussbild, erst „Nachspielen“ klappt sie auf | |
| 776 | 777 | |
| 777 | 778 | if self.split.get_show_sidebar(): |
| 778 | 779 | self._movelist_update() |
| @@ -1191,17 +1192,45 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1191 | 1192 | return worker.call(maia_probabilities(position, elo), timeout=10) |
| 1192 | 1193 | return (ask_maia if worker is not None else None), ("Typisch" if self.mode == "duo" else f"Maia {elo}") |
| 1193 | 1194 | |
| 1195 | + MAIA_SUGGESTIONS = 3 # so viele Antworten schlägt Maia als Pfeile vor | |
| 1196 | + MAIA_SUGGEST_MIN = 0.05 # seltenere Züge zeigt sie nicht | |
| 1197 | + | |
| 1198 | + def _maia_suggest(self, demo, node): | |
| 1199 | + """Keine Vorschläge an ``node`` (z. B. beim besten Zug kürzt die Erklärung die Antworten weg): | |
| 1200 | + Maia fragen, was ein Mensch dieser Stärke hier zieht, als anklickbare Pfeile.""" | |
| 1201 | + tree = demo["tree"] | |
| 1202 | + if explain.suggestions(tree, node) or not self.maia_ready or node.board().is_game_over(): | |
| 1203 | + return | |
| 1204 | + | |
| 1205 | + def done(found, error): | |
| 1206 | + if error is not None or not found or explain.suggestions(tree, node): | |
| 1207 | + return | |
| 1208 | + game = chess.pgn.Game() | |
| 1209 | + game.setup(node.board()) | |
| 1210 | + sub = explain.Tree(game, start=tree.position(node), hero=tree.hero) | |
| 1211 | + for move, prob in found[:self.MAIA_SUGGESTIONS]: | |
| 1212 | + if prob is None or prob >= self.MAIA_SUGGEST_MIN: | |
| 1213 | + sub.info(game.add_variation(move))["maia"] = prob | |
| 1214 | + tree.info(node)["suggest"] = [(child, sub) for child in game.variations] | |
| 1215 | + if self.demo is demo and demo["node"] is node: | |
| 1216 | + self._refresh() | |
| 1217 | + self._coach_show() | |
| 1218 | + self.maia.submit(maia_probabilities(tree.position(node), self._opponent_elo()), done) | |
| 1219 | + | |
| 1194 | 1220 | def _demo_explore(self, demo, node, move): |
| 1195 | 1221 | """Analysebrett: zum selbst gezogenen Zug eine Nebenvariante berechnen und einhängen.""" |
| 1196 | 1222 | tree = demo["tree"] |
| 1197 | 1223 | maia, name = self._tree_maia() |
| 1198 | 1224 | |
| 1199 | 1225 | def on_done(sub, error): |
| 1200 | - child = graft(tree, node, sub) if error is None and sub is not None and sub.first() else None | |
| 1226 | + # nur der eigene Zug kommt in den Baum; Antworten stehen als anklickbare Pfeile daneben | |
| 1227 | + child = graft_move(tree, node, sub) if error is None and sub is not None and sub.first() else None | |
| 1201 | 1228 | if child is not None and demo["chosen"].get(node) is None: |
| 1202 | 1229 | demo["chosen"][node] = child |
| 1203 | 1230 | if child is not None and demo.get("game"): |
| 1204 | 1231 | self._schedule_autosave() # die neue Variante gehört zum Spielstand |
| 1232 | + if child is not None: | |
| 1233 | + self._maia_suggest(demo, child) | |
| 1205 | 1234 | self._demo_grafted(demo, child, error) |
| 1206 | 1235 | |
| 1207 | 1236 | job = explore_job(tree.position(node), move, tree.hero, maia, name) |
| @@ -1482,12 +1511,13 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1482 | 1511 | self._refresh() |
| 1483 | 1512 | return |
| 1484 | 1513 | last = len(self.board.move_stack) - 1 |
| 1485 | - if ply is None or ply >= last and self.mode != "review": | |
| 1486 | - self._end_browse() # „Zur aktuellen Stellung“ oder der letzte Zug: zurück ins Spiel | |
| 1487 | - if self.demo is not None and self.demo.get("game"): | |
| 1488 | - self._analysis_open(last) # Spiel vorbei oder „review“: das Ende auf dem Analysebrett | |
| 1514 | + if ply is None: | |
| 1515 | + self._end_browse() # „Zur aktuellen Stellung“: zurück ins Spiel bzw. zum Schlussbild | |
| 1489 | 1516 | return |
| 1490 | - self._analysis_open(min(ply, last)) | |
| 1517 | + if ply >= last and self.mode != "review" and not self._over(): | |
| 1518 | + self._end_browse() # der letzte Zug einer laufenden Partie: zurück ins Spiel | |
| 1519 | + return | |
| 1520 | + self._analysis_open(min(ply, last)) # nach der Partie: Nachspielen (siehe _analysis_open) | |
| 1491 | 1521 | |
| 1492 | 1522 | def _movelist_update(self): |
| 1493 | 1523 | """Zugliste samt Nebenvarianten vom Analysebrett; markiert, wo das Analysebrett gerade steht.""" |
| @@ -1507,7 +1537,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1507 | 1537 | """Markierte Zeile in der Zugliste: beim Analysebrett der Zug der Partie, an dem man gerade ist.""" |
| 1508 | 1538 | if self.demo is not None and self.demo.get("game"): |
| 1509 | 1539 | ply = self._game_ply(self.demo["node"]) |
| 1510 | - return None if ply >= len(self.board.move_stack) - 1 and self.mode != "review" else ply | |
| 1540 | + return None if ply >= len(self.board.move_stack) - 1 and not self.replaying else ply | |
| 1511 | 1541 | return self.browse_ply |
| 1512 | 1542 | |
| 1513 | 1543 | def _on_key(self, _controller, keyval, _keycode, state): |
| @@ -1691,8 +1721,6 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1691 | 1721 | if pasted.orientation is not None: |
| 1692 | 1722 | target.view.flipped = pasted.orientation == chess.BLACK |
| 1693 | 1723 | target.view.queue_draw() |
| 1694 | - if state.board.move_stack: | |
| 1695 | - target.list_btn.set_active(True) # eingefügte Partie: gleich mit Zugliste und Bewertung | |
| 1696 | 1724 | if not state.board.move_stack: |
| 1697 | 1725 | side = "Weiß" if state.board.turn == chess.WHITE else "Schwarz" |
| 1698 | 1726 | text = f"Stellung eingefügt – du spielst {side} gegen Maia" |
| @@ -1972,10 +2000,9 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1972 | 2000 | self.view.flipped = self.human == chess.BLACK |
| 1973 | 2001 | self._changed() |
| 1974 | 2002 | self._refresh() |
| 2003 | + if self._foreign() or self.mode == "review" or self._over(): | |
| 2004 | + self._replay_start() # geöffnete fertige oder fremde Partie: gleich nachspielen | |
| 1975 | 2005 | if self.mode == "review": |
| 1976 | - if not self.end_shown: | |
| 1977 | - self.list_btn.set_active(True) | |
| 1978 | - self.end_shown = True | |
| 1979 | 2006 | self._analyze_review() |
| 1980 | 2007 | elif not self._over() and self.board.turn != self.human: |
| 1981 | 2008 | self._request_maia_move() |
| @@ -2005,7 +2032,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 2005 | 2032 | dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED) |
| 2006 | 2033 | dialog.set_default_response("save") |
| 2007 | 2034 | dialog.set_close_response("cancel") |
| 2008 | - default = self.save_name or f"Partie vom {datetime.datetime.now():%d.%m. %H:%M}" | |
| 2035 | + default = self.save_name or f"Partie vom {datetime.datetime.now():%d.%m.%y %H:%M}" | |
| 2009 | 2036 | entry = Gtk.Entry(text=default, activates_default=True, width_request=300) |
| 2010 | 2037 | dialog.set_extra_child(entry) |
| 2011 | 2038 | |
added schach/endbar.py +59 −0
| @@ -0,0 +1,59 @@ | ||
| 1 | +"""Graue Leiste über dem Brett wie ``Adw.Banner``, aber mit mehreren Knöpfen. | |
| 2 | + | |
| 3 | +Nach der Partie: „Nachspielen“ und „Neue Partie“; beim Nachspielen „Ab hier weiterspielen“. | |
| 4 | +Aussehen aus dem Stil von libadwaita übernommen (``banner > revealer > widget``). | |
| 5 | +""" | |
| 6 | + | |
| 7 | +import gi | |
| 8 | + | |
| 9 | +gi.require_version("Gtk", "4.0") | |
| 10 | +from gi.repository import Gtk # noqa: E402 | |
| 11 | + | |
| 12 | +CSS = b""" | |
| 13 | +.end-bar { | |
| 14 | + background-color: color-mix(in srgb, #7d7d83 30%, var(--window-bg-color)); | |
| 15 | + color: var(--window-fg-color); | |
| 16 | + padding: 6px; | |
| 17 | +} | |
| 18 | +.end-bar:backdrop { background-color: color-mix(in srgb, #7d7d83 15%, var(--window-bg-color)); } | |
| 19 | +.end-bar:backdrop > label, .end-bar:backdrop > box { filter: opacity(0.5); } | |
| 20 | +""" | |
| 21 | + | |
| 22 | + | |
| 23 | +class EndBar(Gtk.Revealer): | |
| 24 | + def __init__(self): | |
| 25 | + super().__init__(transition_type=Gtk.RevealerTransitionType.SLIDE_DOWN) | |
| 26 | + provider = Gtk.CssProvider() | |
| 27 | + provider.load_from_data(CSS) | |
| 28 | + Gtk.StyleContext.add_provider_for_display(self.get_display(), provider, | |
| 29 | + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) | |
| 30 | + bar = Gtk.Box(spacing=6, css_classes=["end-bar"]) | |
| 31 | + # links so viel Platz wie rechts die Knöpfe brauchen: der Text steht in der Mitte des Fensters | |
| 32 | + self._balance = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL) | |
| 33 | + spacer = Gtk.Box() | |
| 34 | + self.label = Gtk.Label(hexpand=True, wrap=True, justify=Gtk.Justification.CENTER, | |
| 35 | + margin_start=6, margin_end=6) | |
| 36 | + self.label.add_css_class("heading") | |
| 37 | + self.buttons = Gtk.Box(spacing=6, halign=Gtk.Align.END) | |
| 38 | + self._balance.add_widget(spacer) | |
| 39 | + self._balance.add_widget(self.buttons) | |
| 40 | + bar.append(spacer) | |
| 41 | + bar.append(self.label) | |
| 42 | + bar.append(self.buttons) | |
| 43 | + self.set_child(bar) | |
| 44 | + self._shown = None | |
| 45 | + | |
| 46 | + def show(self, title, buttons=()): | |
| 47 | + """``buttons``: [(Beschriftung, Aktion)], der letzte ist der Hauptknopf. ``title`` None: zu.""" | |
| 48 | + if title is None: | |
| 49 | + self.set_reveal_child(False) | |
| 50 | + return | |
| 51 | + if (title, tuple(buttons)) != self._shown: | |
| 52 | + self._shown = (title, tuple(buttons)) | |
| 53 | + self.label.set_label(title) | |
| 54 | + while (child := self.buttons.get_first_child()) is not None: | |
| 55 | + self.buttons.remove(child) | |
| 56 | + for label, action in buttons: | |
| 57 | + self.buttons.append(Gtk.Button(label=label, action_name=action, valign=Gtk.Align.CENTER, | |
| 58 | + use_underline=True)) | |
| 59 | + self.set_reveal_child(True) | |
modified schach/explain.py +43 −0
| @@ -781,6 +781,49 @@ def explore_job(board, move, hero, maia= | ||
| 781 | 781 | return job |
| 782 | 782 | |
| 783 | 783 | |
| 784 | +def _adopt(tree, node, source, sub): | |
| 785 | + """``source`` (Knoten in ``sub``) als Kind von ``node`` übernehmen, ohne seine Fortsetzungen: | |
| 786 | + die werden Vorschläge (meta "suggest"), die man erst anklicken muss.""" | |
| 787 | + new = next((c for c in node.variations if c.move == source.move), None) | |
| 788 | + if new is None: | |
| 789 | + new = node.add_variation(source.move, comment=source.comment) | |
| 790 | + tree.meta[new] = dict(sub.meta.get(source, {})) | |
| 791 | + tree.info(new)["suggest"] = [(child, sub) for child in source.variations] | |
| 792 | + return new | |
| 793 | + | |
| 794 | + | |
| 795 | +def graft_move(tree, node, sub): | |
| 796 | + """Nur den selbst gezogenen Zug aus ``sub`` (Wurzel = Stellung an ``node``) einhängen. Die | |
| 797 | + Antworten darauf (Maia, Stockfish) zieht niemand von selbst: Sie stehen als Vorschläge daneben.""" | |
| 798 | + first = sub.first() | |
| 799 | + return _adopt(tree, node, first, sub) if first is not None else None | |
| 800 | + | |
| 801 | + | |
| 802 | +def suggestion_label(meta): | |
| 803 | + """Schild am Vorschlagspfeil: „Maia oft“, „Maia selten“ …, sonst „Bester Zug“ (Stockfish).""" | |
| 804 | + if meta.get("label"): | |
| 805 | + return meta["label"] | |
| 806 | + if meta.get("maia") is not None: | |
| 807 | + return f"Maia {chance_word(meta['maia'])}" | |
| 808 | + return "Bester Zug" if meta.get("best") else "" | |
| 809 | + | |
| 810 | + | |
| 811 | +def suggestions(tree, node): | |
| 812 | + """Vorschläge an ``node``, die noch kein Kind sind: [(Zug, Schild)].""" | |
| 813 | + taken = {c.move for c in node.variations} | |
| 814 | + return [(child.move, suggestion_label(sub.meta.get(child, {}))) | |
| 815 | + for child, sub in tree.meta.get(node, {}).get("suggest", ()) if child.move not in taken] | |
| 816 | + | |
| 817 | + | |
| 818 | +def take_suggestion(tree, node, move): | |
| 819 | + """Vorschlag ``move`` an ``node`` angeklickt: als Kind einhängen (seine Fortsetzungen werden | |
| 820 | + wieder Vorschläge). Gibt den Knoten zurück.""" | |
| 821 | + for child, sub in tree.meta.get(node, {}).get("suggest", ()): | |
| 822 | + if child.move == move: | |
| 823 | + return _adopt(tree, node, child, sub) | |
| 824 | + return None | |
| 825 | + | |
| 826 | + | |
| 784 | 827 | def graft(tree, node, sub): |
| 785 | 828 | """Den Baum ``sub`` (Wurzel = Stellung an ``node``) unter ``node`` einhängen; gibt den Knoten |
| 786 | 829 | zurück, der ``sub.first()`` entspricht.""" |
modified schach/exportdialog.py +1 −1
| @@ -26,7 +26,7 @@ SWITCHES = [ | ||
| 26 | 26 | ("players", "Spielerköpfe", "Namen, Datum und Ergebnis"), |
| 27 | 27 | ("last_move", "Letzten Zug markieren", "Felder des letzten Zugs hervorheben"), |
| 28 | 28 | ("flipped", "Schwarz unten", "Brett gedreht"), |
| 29 | - ("variations", "Varianten", "Selbst gezogene Züge vom Analysebrett"), | |
| 29 | + ("variations", "Varianten", "Selbst gezogene Züge vom Nachspielen"), | |
| 30 | 30 | ("takebacks", "Zurückgenommene Züge", "Fehlversuche und Rücknahmen als Nebenvariante"), |
| 31 | 31 | ("move_times", "Zugzeit", "Wie lange jeder Zug gedauert hat"), |
| 32 | 32 | ] |
modified schach/movelist.py +75 −70
| @@ -1,6 +1,8 @@ | ||
| 1 | -"""Zugliste für die Analyse: ein Halbzug pro Zeile, dahinter ein Weiß/Schwarz-Balken. | |
| 1 | +"""Zugliste: ein Halbzug pro Zeile, dahinter ein Weiß/Schwarz-Balken. | |
| 2 | 2 | |
| 3 | -Nebenvarianten vom Analysebrett hängen als Baum darunter: aufklappbar, jeder Zug anklickbar. | |
| 3 | +Nebenvarianten vom Nachspielen hängen als Baum darunter, ebenfalls ein Zug pro Zeile. Zweigt an | |
| 4 | +einem Zug genau eine Variante ab, klappt er sie direkt auf; bei mehreren steht dazwischen eine Ebene | |
| 5 | +mit „Variante 1“, „Variante 2“ …, die man einzeln aufklappt. | |
| 4 | 6 | Tastatur wie bei Bäumen üblich: ↑/↓ durch die sichtbaren Zeilen (zugeklappt: nur die Partie), |
| 5 | 7 | → klappt auf bzw. geht in die erste Variante, ← klappt zu bzw. zurück zur Zeile darüber.""" |
| 6 | 8 | |
| @@ -32,15 +34,10 @@ CSS = b""" | ||
| 32 | 34 | font-feature-settings: "tnum"; |
| 33 | 35 | } |
| 34 | 36 | .move-row-buttons button { min-height: 22px; min-width: 22px; padding: 1px; } |
| 35 | -.variation-row { padding: 2px 8px 2px 0; } | |
| 36 | -.variation-pill { | |
| 37 | - background: alpha(@accent_bg_color, 0.12); | |
| 38 | - border-radius: 6px; | |
| 39 | - padding: 1px 7px; | |
| 40 | - font-size: smaller; | |
| 41 | -} | |
| 42 | -.variation-pill link, .variation-pill link:visited { color: inherit; text-decoration-line: none; } | |
| 37 | +.move-pill.variation-move { background: mix(@accent_bg_color, white, 0.82); } | |
| 38 | +.move-pill.variation-move.selected-move { background: @accent_bg_color; color: @accent_fg_color; } | |
| 43 | 39 | .tree-toggle { min-height: 20px; min-width: 20px; padding: 0; } |
| 40 | +.variation-head { font-style: italic; padding: 4px 0; } | |
| 44 | 41 | """ |
| 45 | 42 | |
| 46 | 43 | |
| @@ -89,7 +86,6 @@ class MoveList(Gtk.Box): | ||
| 89 | 86 | self._token_rows = {} # Nummer eines Variantenzugs -> Zeile, in der er steht |
| 90 | 87 | self._selected = None |
| 91 | 88 | self._selected_variation = None |
| 92 | - self._link_clicked = 0 # Zeitpunkt des letzten Klicks auf einen Zug in einer Variante | |
| 93 | 89 | self._signature = None |
| 94 | 90 | self._updating = False |
| 95 | 91 | |
| @@ -100,7 +96,8 @@ class MoveList(Gtk.Box): | ||
| 100 | 96 | |
| 101 | 97 | ``variations``: {Halbzug: Zweige} – Nebenvarianten vom Analysebrett, aufklappbar unter dem Zug, |
| 102 | 98 | nach dem sie abzweigen (-1: vor dem ersten Zug, immer offen). Zweig = ((Nummer, Zugnummer, Zug, |
| 103 | - Unterzweige), …), siehe ``training._list_variations``. ``selected_variation``: Nummer darin. | |
| 99 | + Unterzweige, Gewinnchance Weiß, Name), …), siehe ``training._list_variations``. | |
| 100 | + ``selected_variation``: Nummer des gewählten Variantenzugs. | |
| 104 | 101 | ``times``: {Halbzug: ms} – Bedenkzeit, rechts in der Zeile.""" |
| 105 | 102 | moves = list(board.move_stack) |
| 106 | 103 | times = times or {} |
| @@ -121,8 +118,7 @@ class MoveList(Gtk.Box): | ||
| 121 | 118 | self._toggles = {} |
| 122 | 119 | self._token_rows = {} |
| 123 | 120 | ordered = [] |
| 124 | - for branch in after.get(-1, ()): | |
| 125 | - ordered += self._branch_rows(branch, (), None, 0) | |
| 121 | + ordered += self._fork_rows(after.get(-1, ()), (), None, 1) | |
| 126 | 122 | replay = board.root() |
| 127 | 123 | for ply, move in enumerate(moves): |
| 128 | 124 | number = replay.fullmove_number |
| @@ -134,8 +130,7 @@ class MoveList(Gtk.Box): | ||
| 134 | 130 | key, indent=bool(after)) |
| 135 | 131 | self._rows.append((row, buttons)) |
| 136 | 132 | ordered.append(row) |
| 137 | - for branch in after.get(ply, ()): | |
| 138 | - ordered += self._branch_rows(branch, (key,), row, 1) | |
| 133 | + ordered += self._fork_rows(after.get(ply, ()), (key,), row, 1) | |
| 139 | 134 | for row in ordered: |
| 140 | 135 | self.listbox.append(row) |
| 141 | 136 | self._show_open() |
| @@ -156,14 +151,16 @@ class MoveList(Gtk.Box): | ||
| 156 | 151 | self._toggles[key] = button |
| 157 | 152 | return button |
| 158 | 153 | |
| 159 | - def _make_row(self, ply, prefix, san, symbol, white_pct, ms=None, key=None, indent=False): | |
| 154 | + def _make_row(self, ply, prefix, san, symbol, white_pct, ms=None, key=None, indent=False, token=None, depth=0): | |
| 155 | + """Zeile für einen Zug der Partie (``ply``) oder einer Variante (``token``, eingerückt um ``depth``).""" | |
| 160 | 156 | bar = Gtk.DrawingArea(content_height=30, hexpand=True) |
| 161 | 157 | bar.set_draw_func(self._draw_bar, white_pct) |
| 162 | 158 | |
| 163 | 159 | text = f"<span alpha='60%'>{prefix}</span> <b>{san}</b>" |
| 164 | 160 | if symbol: |
| 165 | 161 | text += f" <span foreground='{_hex(BADGE[symbol])}' weight='heavy'>{symbol}</span>" |
| 166 | - pill = Gtk.Label(use_markup=True, label=text, css_classes=["move-pill"], valign=Gtk.Align.CENTER) | |
| 162 | + pill = Gtk.Label(use_markup=True, label=text, valign=Gtk.Align.CENTER, | |
| 163 | + css_classes=["move-pill"] + (["variation-move"] if token is not None else [])) | |
| 167 | 164 | |
| 168 | 165 | copy_btn = Gtk.Button( |
| 169 | 166 | icon_name="edit-copy-symbolic", tooltip_text="Stellung als FEN kopieren", css_classes=["osd", "circular"] |
| @@ -177,15 +174,16 @@ class MoveList(Gtk.Box): | ||
| 177 | 174 | buttons = Gtk.Box(spacing=4, css_classes=["move-row-buttons"], valign=Gtk.Align.CENTER, visible=False) |
| 178 | 175 | if symbol in ("?!", "?", "??"): |
| 179 | 176 | why_btn = Gtk.Button(icon_name="dialog-question-symbolic", css_classes=["osd", "circular"], |
| 180 | - tooltip_text="Warum nicht? – zeigt auf dem Analysebrett, was dagegen spricht") | |
| 177 | + tooltip_text="Warum nicht? – zeigt beim Nachspielen, was dagegen spricht") | |
| 181 | 178 | why_btn.connect("clicked", lambda *_: self.on_why_not and self.on_why_not(ply)) |
| 182 | 179 | buttons.append(why_btn) |
| 183 | - buttons.append(copy_btn) | |
| 184 | - buttons.append(play_btn) | |
| 180 | + if token is None: | |
| 181 | + buttons.append(copy_btn) | |
| 182 | + buttons.append(play_btn) | |
| 185 | 183 | |
| 186 | - content = Gtk.Box(spacing=6, margin_start=2 if indent else 8, margin_end=8) | |
| 184 | + content = Gtk.Box(spacing=6, margin_start=(2 if indent else 8) + 16 * depth, margin_end=8) | |
| 187 | 185 | if key is not None: |
| 188 | - content.append(self._toggle_button(key, "Nebenvarianten zeigen")) | |
| 186 | + content.append(self._toggle_button(key, "Varianten zeigen")) | |
| 189 | 187 | elif indent: # Platz wie der Knopf daneben, damit die Züge untereinander stehen |
| 190 | 188 | content.append(Gtk.Box(width_request=20)) |
| 191 | 189 | content.append(pill) |
| @@ -199,8 +197,12 @@ class MoveList(Gtk.Box): | ||
| 199 | 197 | overlay.add_overlay(content) |
| 200 | 198 | row = Gtk.ListBoxRow(child=overlay) |
| 201 | 199 | row.ply = ply |
| 200 | + row.variation = token | |
| 202 | 201 | row.pill = pill |
| 203 | 202 | row.key, row.needs, row.parent_row = key, (), None |
| 203 | + if token is not None: | |
| 204 | + row.set_tooltip_text("Variante") | |
| 205 | + return row, buttons | |
| 204 | 206 | # Knöpfe schon beim Darüberfahren zeigen |
| 205 | 207 | hover = Gtk.EventControllerMotion() |
| 206 | 208 | hover.connect("enter", lambda *_: buttons.set_visible(True)) |
| @@ -208,48 +210,44 @@ class MoveList(Gtk.Box): | ||
| 208 | 210 | row.add_controller(hover) |
| 209 | 211 | return row, buttons |
| 210 | 212 | |
| 211 | - def _branch_rows(self, branch, needs, parent_row, depth): | |
| 212 | - """Zeile für einen Zweig, darunter (eine Stufe tiefer) die Alternativen innerhalb des Zweigs. | |
| 213 | - ``needs``: Schlüssel, die offen sein müssen, damit die Zeile zu sehen ist.""" | |
| 214 | - subs = [sub for move in branch for sub in move[3]] | |
| 215 | - key = ("zweig", branch[0][0]) if subs else None | |
| 216 | - pill = Gtk.Label(use_markup=True, css_classes=["variation-pill"], wrap=True, xalign=0, hexpand=False, | |
| 217 | - halign=Gtk.Align.START) | |
| 218 | - pill.connect("activate-link", self._on_link) | |
| 219 | - content = Gtk.Box(spacing=4, css_classes=["variation-row"], margin_start=2 + 18 * depth) | |
| 220 | - content.append(self._toggle_button(key, "Untervarianten zeigen") if key else Gtk.Box(width_request=20)) | |
| 221 | - content.append(pill) | |
| 222 | - row = Gtk.ListBoxRow(child=content, tooltip_text="Nebenvariante vom Analysebrett") | |
| 223 | - row.ply = None | |
| 224 | - row.variation = branch[0][0] | |
| 225 | - row.branch = branch | |
| 226 | - row.pill = pill | |
| 227 | - row.key, row.needs, row.parent_row = key, needs, parent_row | |
| 228 | - for move in branch: | |
| 229 | - self._token_rows[move[0]] = row | |
| 230 | - self._variation_rows.append(row) | |
| 231 | - self._branch_markup(row, None) | |
| 232 | - rows = [row] | |
| 233 | - for sub in subs: | |
| 234 | - rows += self._branch_rows(sub, needs + (key,), row, depth + 1) | |
| 213 | + def _fork_rows(self, branches, needs, parent_row, depth): | |
| 214 | + """Varianten, die nach ``parent_row`` abzweigen: eine direkt als Folge, mehrere je unter einer | |
| 215 | + Kopfzeile „Variante n“. ``needs``: Schlüssel, die offen sein müssen, damit sie zu sehen sind.""" | |
| 216 | + names = [branch[0][5] for branch in branches] | |
| 217 | + if len(branches) == 1 and not names[0]: # eine unbenannte Variante: direkt als Folge | |
| 218 | + return self._branch_rows(branches[0], needs, parent_row, depth) | |
| 219 | + rows = [] | |
| 220 | + for number, branch in enumerate(branches, start=1): | |
| 221 | + key = ("variante", branch[0][0]) | |
| 222 | + token, prefix, san = branch[0][:3] | |
| 223 | + title = names[number - 1] or f"Variante {number}" # Name aus dem PGN („( { Name } 10. Lxf7+ … )“) | |
| 224 | + label = Gtk.Label(use_markup=True, xalign=0, ellipsize=3, # 3 = Pango.EllipsizeMode.END | |
| 225 | + label=f"{title} <span alpha='55%'>· {prefix} {san}</span>") | |
| 226 | + content = Gtk.Box(spacing=6, css_classes=["variation-head"], margin_start=2 + 16 * depth) | |
| 227 | + content.append(self._toggle_button(key, "Variante zeigen")) | |
| 228 | + content.append(label) | |
| 229 | + row = Gtk.ListBoxRow(child=content) | |
| 230 | + row.ply = row.variation = None | |
| 231 | + row.pill = label | |
| 232 | + row.key, row.needs, row.parent_row = key, needs, parent_row | |
| 233 | + self._variation_rows.append(row) | |
| 234 | + rows.append(row) | |
| 235 | + rows += self._branch_rows(branch, needs + (key,), row, depth + 1) | |
| 235 | 236 | return rows |
| 236 | 237 | |
| 237 | - @staticmethod | |
| 238 | - def _branch_markup(row, selected): | |
| 239 | - words = [] | |
| 240 | - for token, prefix, san, _subs in row.branch: | |
| 241 | - word = f"{prefix} {san}" if prefix else san | |
| 242 | - if token == selected: | |
| 243 | - word = f"<span background='#3584e4' foreground='white'><b> {word} </b></span>" | |
| 244 | - words.append(f"<a href='{token}' title=''>{word}</a>") | |
| 245 | - row.pill.set_markup("↳ " + " ".join(words)) | |
| 246 | - row.marked = selected | |
| 247 | - | |
| 248 | - def _on_link(self, _label, uri): | |
| 249 | - self._link_clicked = GLib.get_monotonic_time() # Zeile wird beim selben Klick gewählt: nicht ihr erster Zug | |
| 250 | - if self.on_variation and uri.isdigit(): | |
| 251 | - self.on_variation(int(uri)) | |
| 252 | - return True | |
| 238 | + def _branch_rows(self, branch, needs, parent_row, depth): | |
| 239 | + """Ein Zug pro Zeile. Was nach einem Zug abzweigt, steht direkt darunter, eine Stufe tiefer | |
| 240 | + und aufklappbar (siehe _fork_rows).""" | |
| 241 | + rows = [] | |
| 242 | + for token, prefix, san, subs, white, _name in branch: | |
| 243 | + key = ("zweig", token) if subs else None | |
| 244 | + row, _ = self._make_row(None, prefix, san, None, white, key=key, indent=True, token=token, depth=depth) | |
| 245 | + row.needs, row.parent_row = needs, parent_row | |
| 246 | + self._token_rows[token] = row | |
| 247 | + self._variation_rows.append(row) | |
| 248 | + rows.append(row) | |
| 249 | + rows += self._fork_rows(subs, needs + (key,), row, depth + 1) | |
| 250 | + return rows | |
| 253 | 251 | |
| 254 | 252 | # --- Auf- und Zuklappen ------------------------------------------------ |
| 255 | 253 | |
| @@ -334,9 +332,12 @@ class MoveList(Gtk.Box): | ||
| 334 | 332 | self._updating = False |
| 335 | 333 | self._show_buttons(None if selected_variation is not None else selected) |
| 336 | 334 | for row in self._variation_rows: |
| 337 | - marked = self._selected_variation if row is holder else None | |
| 338 | - if getattr(row, "marked", None) != marked: | |
| 339 | - self._branch_markup(row, marked) | |
| 335 | + if row.variation is None: | |
| 336 | + continue | |
| 337 | + if row is holder: | |
| 338 | + row.pill.add_css_class("selected-move") | |
| 339 | + else: | |
| 340 | + row.pill.remove_css_class("selected-move") | |
| 340 | 341 | self.live_btn.set_sensitive(selected is not None or holder is not None) |
| 341 | 342 | |
| 342 | 343 | def _show_buttons(self, selected): |
| @@ -351,15 +352,19 @@ class MoveList(Gtk.Box): | ||
| 351 | 352 | def _on_row_selected(self, listbox, row): |
| 352 | 353 | if self._updating: |
| 353 | 354 | return |
| 354 | - if row is not None and getattr(row, "variation", None) is not None: | |
| 355 | + # erst nach dem Klick reagieren: die App baut die Liste dabei womöglich neu, und GTK darf die | |
| 356 | + # Zeile, deren Signal gerade läuft, nicht unter sich verlieren (sonst Absturz) | |
| 357 | + if row is not None and row.variation is not None: | |
| 355 | 358 | GLib.idle_add(self._row_chosen, row) |
| 356 | 359 | return |
| 357 | - self._select(row.ply if row is not None else None) | |
| 360 | + if row is not None and row.ply is None: # Kopfzeile „Variante n“: nur Auf- und Zuklappen | |
| 361 | + return | |
| 362 | + ply = row.ply if row is not None else None | |
| 363 | + GLib.idle_add(lambda: self._select(ply) and False) | |
| 358 | 364 | |
| 359 | 365 | def _row_chosen(self, row): |
| 360 | 366 | """Variantenzeile gewählt (Tastatur, Klick neben die Züge): ihr erster Zug.""" |
| 361 | - recent = GLib.get_monotonic_time() - self._link_clicked < 500_000 # gerade einen Zug angeklickt | |
| 362 | - if not recent and self.on_variation and self._token_rows.get(self._selected_variation) is not row: | |
| 367 | + if self.on_variation and self._token_rows.get(self._selected_variation) is not row: | |
| 363 | 368 | if row.get_parent() is self.listbox: |
| 364 | 369 | self.on_variation(row.variation) |
| 365 | 370 | return GLib.SOURCE_REMOVE |
modified schach/online.py +1 −1
| @@ -590,7 +590,7 @@ class OnlineMixin: | ||
| 590 | 590 | title="Noch keine Partien auf Lichess")) |
| 591 | 591 | return |
| 592 | 592 | page = Adw.PreferencesPage() |
| 593 | - group = Adw.PreferencesGroup(description="Anklicken öffnet die Partie mit Zugliste und Analyse.") | |
| 593 | + group = Adw.PreferencesGroup(description="Anklicken öffnet die Partie zum Nachspielen.") | |
| 594 | 594 | page.add(group) |
| 595 | 595 | for item in items: |
| 596 | 596 | try: |
modified schach/prefs.py +1 −1
| @@ -78,7 +78,7 @@ class Preferences(Adw.PreferencesDialog) | ||
| 78 | 78 | glyphs = Adw.SwitchRow( |
| 79 | 79 | title="Zugzeichen sofort zeigen", |
| 80 | 80 | subtitle="!, ? und ?? gleich nach dem Zug auf dem Brett. Ausgeschaltet stehen sie " |
| 81 | - "nur in der Zugliste und in der Analyse.", | |
| 81 | + "nur in der Zugliste und beim Nachspielen.", | |
| 82 | 82 | active=bool(settings.get("live_glyphs", True)), |
| 83 | 83 | ) |
| 84 | 84 | glyphs.connect("notify::active", lambda row, _p: self._set("live_glyphs", row.get_active())) |
modified schach/savegames.py +7 −5
| @@ -40,8 +40,9 @@ class GameState: | ||
| 40 | 40 | opponent: str = "" # Gegnername, wenn nicht Maia |
| 41 | 41 | final_text: str = "" # Partie-Ende, das nicht am Brett ablesbar ist (Aufgabe, Zeit …) |
| 42 | 42 | names: tuple = () # (Weiß, Schwarz) bei fremden Partien, an denen man selbst nicht beteiligt war |
| 43 | - # Nebenvarianten vom Analysebrett: {Halbzug: [Variante]}, hängen nach diesem Halbzug (-1: vor dem | |
| 44 | - # ersten Zug). Variante = (Zug, Kommentar, Pfeile ((von, nach, Farbe), …), [Fortsetzungen]) | |
| 43 | + # Nebenvarianten vom Nachspielen: {Halbzug: [Variante]}, hängen nach diesem Halbzug (-1: vor dem | |
| 44 | + # ersten Zug). Variante = (Zug, Kommentar, Pfeile ((von, nach, Farbe), …), [Fortsetzungen], Name); | |
| 45 | + # Name (darf fehlen): Kommentar vor dem ersten Zug, im PGN „( { Name } 10. Lxf7+ … )“ | |
| 45 | 46 | variations: dict = dataclasses.field(default_factory=dict) |
| 46 | 47 | # Zurückgenommene Züge (vom Kurs oder selbst), gleiches Format wie ``variations``. Im PGN eine |
| 47 | 48 | # Nebenvariante mit [%zurueck kurs] bzw. [%zurueck selbst] im Kommentar des ersten Zugs. |
| @@ -182,7 +183,8 @@ def read_variations(game): | ||
| 182 | 183 | def pack(node): |
| 183 | 184 | shapes = read_shapes(node) |
| 184 | 185 | comment = " ".join(COMMAND_RE.sub(" ", node.comment or "").split()) |
| 185 | - return (node.move, comment, shapes, [pack(child) for child in node.variations]) | |
| 186 | + name = " ".join((node.starting_comment or "").split()) | |
| 187 | + return (node.move, comment, shapes, [pack(child) for child in node.variations], name) | |
| 186 | 188 | found, node, ply = {}, game, -1 |
| 187 | 189 | while node.variations: |
| 188 | 190 | if len(node.variations) > 1: |
| @@ -192,10 +194,10 @@ def read_variations(game): | ||
| 192 | 194 | |
| 193 | 195 | |
| 194 | 196 | def _add_variation(parent, variation): |
| 195 | - move, comment, shapes, children = variation | |
| 197 | + move, comment, shapes, children, *name = variation | |
| 196 | 198 | if move not in parent.board().legal_moves: |
| 197 | 199 | return |
| 198 | - node = parent.add_variation(move, comment=comment or "") | |
| 200 | + node = parent.add_variation(move, comment=comment or "", starting_comment=name[0] if name else "") | |
| 199 | 201 | _set_shapes(node, shapes) |
| 200 | 202 | for child in children: |
| 201 | 203 | _add_variation(node, child) |
modified schach/training.py +102 −26
| @@ -463,11 +463,28 @@ class OpeningMixin: | ||
| 463 | 463 | self._refresh() |
| 464 | 464 | self._coach_show() |
| 465 | 465 | |
| 466 | + def _demo_choices(self, node): | |
| 467 | + """Pfeile an ``node``: erst die vorhandenen Zweige, dann noch nicht gezogene Vorschläge | |
| 468 | + (z. B. Maias Antworten auf den eigenen Zug). [(Zug, Schild)]""" | |
| 469 | + tree = self.demo["tree"] | |
| 470 | + return [(c.move, tree.label(c)) for c in node.variations] + explain.suggestions(tree, node) | |
| 471 | + | |
| 466 | 472 | def _demo_choose(self, index): |
| 467 | - """Klick auf einen Pfeil an der Gabelung: diesen Zweig nehmen.""" | |
| 473 | + """Klick auf einen Pfeil: vorhandenen Zweig nehmen oder den Vorschlag einhängen.""" | |
| 468 | 474 | node = self.demo["node"] if self.demo else None |
| 469 | - if node is not None and 0 <= index < len(node.variations): | |
| 475 | + if node is None or self.demo["busy"]: | |
| 476 | + return | |
| 477 | + if 0 <= index < len(node.variations): | |
| 470 | 478 | self._demo_go(node.variations[index]) |
| 479 | + return | |
| 480 | + choices = self._demo_choices(node) | |
| 481 | + if 0 <= index < len(choices): | |
| 482 | + child = explain.take_suggestion(self.demo["tree"], node, choices[index][0]) | |
| 483 | + if child is not None and self.demo.get("game"): | |
| 484 | + self._schedule_autosave() # gehört jetzt zum Spielstand | |
| 485 | + if child is not None: | |
| 486 | + self._maia_suggest(self.demo, child) # app.py: wie geht es weiter? | |
| 487 | + self._demo_go(child) | |
| 471 | 488 | |
| 472 | 489 | def _demo_go(self, child): |
| 473 | 490 | if child is None or self.demo["busy"]: |
| @@ -509,14 +526,10 @@ class OpeningMixin: | ||
| 509 | 526 | def _demo_end(self): |
| 510 | 527 | if self.demo is None: |
| 511 | 528 | return False |
| 512 | - if self.demo.get("game") and self.mode == "review": | |
| 513 | - present = self._game_node(len(self.board.move_stack) - 1) | |
| 514 | - if self.demo["node"] is present or self.demo["busy"]: | |
| 529 | + if self.demo.get("game") and self.replaying: | |
| 530 | + if self.demo["busy"]: | |
| 515 | 531 | return False |
| 516 | - self.demo["node"] = present # fertige Partie: das Analysebrett bleibt, Esc führt zum Ende | |
| 517 | - self._refresh() | |
| 518 | - self._coach_show() | |
| 519 | - return True | |
| 532 | + self.replaying = False # Nachspielen beendet: zurück zum Schlussbild | |
| 520 | 533 | self.demo = None |
| 521 | 534 | self._refresh() |
| 522 | 535 | self._coach_show() |
| @@ -570,12 +583,12 @@ class OpeningMixin: | ||
| 570 | 583 | tree.info(self._game_node(ply))["shapes"] = tuple(found) |
| 571 | 584 | |
| 572 | 585 | def unpack(parent, pack): |
| 573 | - move, comment, shapes, children = pack | |
| 586 | + move, comment, shapes, children, *name = pack | |
| 574 | 587 | if move not in parent.board().legal_moves: |
| 575 | 588 | return |
| 576 | 589 | node = next((c for c in parent.variations if c.move == move), None) |
| 577 | 590 | if node is None: |
| 578 | - node = parent.add_variation(move, comment=comment or "") | |
| 591 | + node = parent.add_variation(move, comment=comment or "", starting_comment=name[0] if name else "") | |
| 579 | 592 | tree.info(node)["shapes"] = tuple(shapes) |
| 580 | 593 | for child in children: |
| 581 | 594 | unpack(node, child) |
| @@ -605,15 +618,52 @@ class OpeningMixin: | ||
| 605 | 618 | return self.mode in self.ANALYSIS_MODES and bool(self.board.move_stack) |
| 606 | 619 | |
| 607 | 620 | def _analysis_open(self, ply, show=True): |
| 608 | - """Analysebrett an der Stellung nach Halbzug ``ply`` öffnen (auch aus einer anderen Vorführung).""" | |
| 621 | + """Analysebrett an der Stellung nach Halbzug ``ply`` öffnen (auch aus einer anderen Vorführung). | |
| 622 | + Nach der Partie heißt das Nachspielen (← oder Klick in die Zugliste sind Abkürzungen dafür).""" | |
| 623 | + if self._over() or self.mode == "review": | |
| 624 | + self.replaying = True | |
| 609 | 625 | node = self._game_node(ply) |
| 610 | 626 | chosen = self.demo["chosen"] if self.demo is not None and self.demo.get("game") else {} |
| 611 | - self.demo = {"label": "Analysebrett", "tree": self.game_tree, "node": node, "chosen": chosen, | |
| 627 | + label = "Nachspielen" | |
| 628 | + self.demo = {"label": label, "tree": self.game_tree, "node": node, "chosen": chosen, | |
| 612 | 629 | "busy": False, "keep": True, "game": True} |
| 613 | 630 | if show: |
| 614 | 631 | self._refresh() |
| 615 | 632 | self._coach_show() |
| 616 | 633 | |
| 634 | + def _foreign(self): | |
| 635 | + """Fremde Partie (eingefügt, geöffnet), an der man selbst nicht beteiligt war?""" | |
| 636 | + return bool(self.names) and tuple(self.names) != ("Weiß", "Schwarz") # zu zweit gilt als eigene | |
| 637 | + | |
| 638 | + def _replay_start(self): | |
| 639 | + """„Nachspielen“: die fertige Partie von vorn auf dem Analysebrett, mit Zugliste.""" | |
| 640 | + if not self._analysis_allowed(): | |
| 641 | + return | |
| 642 | + self.replaying = True | |
| 643 | + self.list_btn.set_active(True) | |
| 644 | + self._analysis_open(-1) | |
| 645 | + | |
| 646 | + def _replay_continue(self): | |
| 647 | + """„Ab hier weiterspielen“: gegen Maia ab der gezeigten Stellung, in einem neuen Fenster.""" | |
| 648 | + node = self.demo["node"] if self.demo is not None and self.demo.get("game") else None | |
| 649 | + if node is None or self.demo["busy"]: | |
| 650 | + return | |
| 651 | + board = node.board() | |
| 652 | + if self._demo_real(node) and node.parent is not None: | |
| 653 | + state = self.state().truncated(self._game_ply(node)) # mit Zeichen, Bewertung, Varianten | |
| 654 | + else: | |
| 655 | + state = savegames.GameState(board=board, human=self.human, elo=0) | |
| 656 | + state.elo = self.elo or int(self.settings["elo"]) | |
| 657 | + if self.names: # fremde Partie oder zu zweit: man übernimmt die Seite, die am Zug ist | |
| 658 | + state.human = board.turn | |
| 659 | + if board.move_stack: | |
| 660 | + last = board.pop() | |
| 661 | + number = f"{board.fullmove_number}." if board.turn == chess.WHITE else f"{board.fullmove_number}…" | |
| 662 | + state.name = f"Weitergespielt nach {number} {notation.move(board, last, self._notation())}" | |
| 663 | + else: | |
| 664 | + state.name = "Weitergespielt ab der Ausgangsstellung" | |
| 665 | + self.get_application().open_window(state) | |
| 666 | + | |
| 617 | 667 | def _analysis_sync(self): |
| 618 | 668 | """Partie ging weiter oder wurde zurückgenommen: Baum nachführen, Analysebrett notfalls schließen.""" |
| 619 | 669 | if self.demo is None or not self.demo.get("game"): |
| @@ -646,7 +696,8 @@ class OpeningMixin: | ||
| 646 | 696 | return {} |
| 647 | 697 | |
| 648 | 698 | def pack(node): |
| 649 | - return (node.move, node.comment, tree.shapes(node), [pack(c) for c in node.variations]) | |
| 699 | + return (node.move, node.comment, tree.shapes(node), [pack(c) for c in node.variations], | |
| 700 | + node.starting_comment or "") | |
| 650 | 701 | found, node, ply = {}, tree.game, -1 |
| 651 | 702 | while True: |
| 652 | 703 | side = [c for c in node.variations if not tree.meta.get(c, {}).get("played")] |
| @@ -660,8 +711,9 @@ class OpeningMixin: | ||
| 660 | 711 | def _list_variations(self): |
| 661 | 712 | """Nebenvarianten für die Zugliste als Baum: ({Halbzug: Zweige}, Knoten). |
| 662 | 713 | |
| 663 | - Zweig = ((Nummer, Zugnummer, Zug, Unterzweige), …) entlang der Hauptfortsetzung; Unterzweige | |
| 664 | - sind die Alternativen zum nächsten Zug. Nummer: Index in Knoten (für Klicks und Markierung).""" | |
| 714 | + Zweig = ((Nummer, Zugnummer, Zug, Unterzweige, Gewinnchance Weiß, Name), …) entlang der | |
| 715 | + Hauptfortsetzung; Unterzweige sind die Alternativen zum nächsten Zug. Knoten: {Nummer: Knoten} | |
| 716 | + (für Klicks und Markierung). Fehlende Gewinnchancen rechnet Stockfish nach (_node_white).""" | |
| 665 | 717 | tree = self.game_tree |
| 666 | 718 | if tree is None or not self._analysis_allowed() or self._game_tree() is not tree: |
| 667 | 719 | return {}, {} |
| @@ -670,14 +722,14 @@ class OpeningMixin: | ||
| 670 | 722 | def branch(first): |
| 671 | 723 | moves, step, board = [], first, first.parent.board() |
| 672 | 724 | while step is not None: |
| 673 | - prefix = f"{board.fullmove_number}." if board.turn == chess.WHITE else ( | |
| 674 | - f"{board.fullmove_number}…" if not moves else "") | |
| 725 | + prefix = f"{board.fullmove_number}." if board.turn == chess.WHITE else f"{board.fullmove_number}…" | |
| 675 | 726 | san = notation.move(board, step.move, style) |
| 676 | 727 | board.push(step.move) |
| 677 | 728 | token = id(step) # bleibt gleich, wenn Varianten dazukommen (aufgeklappt bleibt aufgeklappt) |
| 678 | 729 | nodes[token] = step |
| 679 | 730 | subs = tuple(branch(alt) for alt in step.variations[1:]) |
| 680 | - moves.append((token, prefix, _escape(san), subs)) | |
| 731 | + name = _escape(" ".join((step.starting_comment or "").split())) if not moves else "" | |
| 732 | + moves.append((token, prefix, _escape(san), subs, self._node_white(tree, step), name)) | |
| 681 | 733 | step = step.variations[0] if step.variations else None |
| 682 | 734 | return tuple(moves) |
| 683 | 735 | |
| @@ -691,6 +743,22 @@ class OpeningMixin: | ||
| 691 | 743 | return found, nodes |
| 692 | 744 | node, ply = main, ply + 1 |
| 693 | 745 | |
| 746 | + def _node_white(self, tree, node): | |
| 747 | + """Gewinnchance von Weiß nach einem Variantenzug (Balken in der Zugliste); beim ersten Mal | |
| 748 | + None, Stockfish rechnet sie dann nach.""" | |
| 749 | + info = tree.info(node) | |
| 750 | + if "white" in info or info.get("white_asked"): | |
| 751 | + return info.get("white") | |
| 752 | + info["white_asked"] = True | |
| 753 | + | |
| 754 | + def done(wp, error): | |
| 755 | + if error is None: | |
| 756 | + info["white"] = round(wp, 1) | |
| 757 | + if self.split.get_show_sidebar(): | |
| 758 | + self._movelist_update() | |
| 759 | + self.stockfish.submit(annotate.white_eval_job(node.board()), done) | |
| 760 | + return None | |
| 761 | + | |
| 694 | 762 | def _analysis_open_node(self, node): |
| 695 | 763 | """Analysebrett an einem Knoten des Partiebaums (z. B. Klick auf eine Variantenzeile).""" |
| 696 | 764 | self._analysis_open(-1, show=False) |
| @@ -757,11 +825,13 @@ class OpeningMixin: | ||
| 757 | 825 | arrows.append((step.move.from_square, step.move.to_square, "hint" if mover == hero else "threat")) |
| 758 | 826 | step = step.parent |
| 759 | 827 | v.shapes = tuple(reversed(arrows)) + tuple(v.shapes) |
| 760 | - if len(node.variations) > 1 and not busy: # Gabelung: alle Zweige als beschriftete Pfeile, anklickbar | |
| 828 | + choices = self._demo_choices(node) | |
| 829 | + if not busy and (len(choices) > 1 or len(choices) > len(node.variations)): | |
| 830 | + # Gabelung oder Vorschläge (Maias Antworten): beschriftete Pfeile, anklickbar | |
| 761 | 831 | color = diagram.HINT if board.turn == hero else diagram.THREAT |
| 762 | - v.branches = tuple((c.move.from_square, c.move.to_square, color, tree.label(c) or | |
| 763 | - notation.move(board, c.move, self._notation())) for c in node.variations) | |
| 764 | - v.imagined = bool(busy) or not self._demo_real(node) | |
| 832 | + v.branches = tuple((move.from_square, move.to_square, color, | |
| 833 | + label or notation.move(board, move, self._notation())) for move, label in choices) | |
| 834 | + v.imagined = bool(busy) or game or not self._demo_real(node) # Nachspielen: durchgehend getönt | |
| 765 | 835 | v.queue_draw() |
| 766 | 836 | self._refresh_chrome() |
| 767 | 837 | |
| @@ -796,15 +866,21 @@ class OpeningMixin: | ||
| 796 | 866 | return _escape(notation.move(board, child.move, style)) + (f" ({_escape(name)})" if name else "") |
| 797 | 867 | markup += (f"\n<span alpha='70%'>Weiter mit >: {option(ahead)}. Oder Pfeil anklicken: " |
| 798 | 868 | + ", ".join(option(c) for c in others) + ".</span>") |
| 869 | + elif not busy and (suggested := explain.suggestions(tree, node)): | |
| 870 | + board = node.board() | |
| 871 | + words = [_escape(notation.move(board, move, style)) + (f" ({_escape(label)})" if label else "") | |
| 872 | + for move, label in suggested] | |
| 873 | + markup += ("\n<span alpha='70%'>Mögliche Antworten – Pfeil anklicken, um sie zu sehen: " | |
| 874 | + + ", ".join(words) + ".</span>") | |
| 799 | 875 | self.coach_label.set_markup(mark_squares(markup)) |
| 800 | 876 | self.coach_nav.set_visible(True) |
| 801 | 877 | self.coach_prev.set_sensitive(depth > 0 and not busy) |
| 802 | 878 | self.coach_next.set_sensitive(bool(node.variations) and not busy) |
| 803 | 879 | self.coach_last.set_visible(False) |
| 804 | 880 | self.coach_first.set_visible(True) |
| 805 | - if self.demo.get("game") and self.mode == "review": | |
| 806 | - self.coach_first.set_tooltip_text("Zum Ende der Partie (Esc)") | |
| 807 | - self.coach_first.set_sensitive(node is not self._game_node(len(self.board.move_stack) - 1)) | |
| 881 | + if self.demo.get("game") and self.replaying: | |
| 882 | + self.coach_first.set_tooltip_text("Nachspielen beenden (Esc)") | |
| 883 | + self.coach_first.set_sensitive(not busy) | |
| 808 | 884 | else: |
| 809 | 885 | self.coach_first.set_tooltip_text("Zurück zur Partie (Esc)") |
| 810 | 886 | self.coach_first.set_sensitive(True) |
modified tests/test_clipboard.py +1 −1
| @@ -37,7 +37,7 @@ class ParseTest(unittest.TestCase): | ||
| 37 | 37 | |
| 38 | 38 | def test_foreign_pgn_keeps_variations(self): |
| 39 | 39 | pasted = clipboard.parse('[White "A"]\n[Black "B"]\n\n1. e4 e5 (1... c5 {Sizilianisch} 2. Nf3) 2. Nf3 *') |
| 40 | - (move, comment, shapes, children), = pasted.state.variations[0] | |
| 40 | + (move, comment, shapes, children, _name), = pasted.state.variations[0] | |
| 41 | 41 | self.assertEqual((move, comment, shapes), (chess.Move.from_uci("c7c5"), "Sizilianisch", ())) |
| 42 | 42 | self.assertEqual(children[0][0], chess.Move.from_uci("g1f3")) |
| 43 | 43 | |
modified tests/test_explain.py +36 −0
| @@ -3,6 +3,7 @@ import unittest | ||
| 3 | 3 | |
| 4 | 4 | import chess |
| 5 | 5 | import chess.engine |
| 6 | +import chess.pgn | |
| 6 | 7 | |
| 7 | 8 | from schach import explain |
| 8 | 9 | |
| @@ -266,3 +267,38 @@ class PawnAttackTest(unittest.TestCase): | ||
| 266 | 267 | |
| 267 | 268 | if __name__ == "__main__": |
| 268 | 269 | unittest.main() |
| 270 | + | |
| 271 | + | |
| 272 | +class SuggestionTest(unittest.TestCase): | |
| 273 | + """Nachspielen: nur der eigene Zug kommt in den Baum, Antworten bleiben anklickbare Vorschläge.""" | |
| 274 | + | |
| 275 | + def sub_tree(self): | |
| 276 | + board = chess.Board() | |
| 277 | + game = chess.pgn.Game() | |
| 278 | + e4 = game.add_variation(chess.Move.from_uci("e2e4"), comment="Du ziehst e4.") | |
| 279 | + e5 = e4.add_variation(chess.Move.from_uci("e7e5")) | |
| 280 | + c5 = e4.add_variation(chess.Move.from_uci("c7c5")) | |
| 281 | + e5.add_variation(chess.Move.from_uci("g1f3")) | |
| 282 | + sub = explain.Tree(game, start=board, hero=chess.WHITE) | |
| 283 | + sub.info(e5).update(maia=0.6) | |
| 284 | + sub.info(c5).update(maia=0.1) | |
| 285 | + return sub | |
| 286 | + | |
| 287 | + def test_only_own_move_is_grafted(self): | |
| 288 | + game = chess.pgn.Game() | |
| 289 | + tree = explain.Tree(game, start=chess.Board(), hero=chess.WHITE) | |
| 290 | + child = explain.graft_move(tree, game, self.sub_tree()) | |
| 291 | + self.assertEqual(child.move, chess.Move.from_uci("e2e4")) | |
| 292 | + self.assertEqual(child.comment, "Du ziehst e4.") | |
| 293 | + self.assertEqual(child.variations, []) | |
| 294 | + self.assertEqual(explain.suggestions(tree, child), | |
| 295 | + [(chess.Move.from_uci("e7e5"), "Maia meistens"), (chess.Move.from_uci("c7c5"), "Maia selten")]) | |
| 296 | + | |
| 297 | + def test_taking_a_suggestion_offers_the_next(self): | |
| 298 | + game = chess.pgn.Game() | |
| 299 | + tree = explain.Tree(game, start=chess.Board(), hero=chess.WHITE) | |
| 300 | + child = explain.graft_move(tree, game, self.sub_tree()) | |
| 301 | + reply = explain.take_suggestion(tree, child, chess.Move.from_uci("e7e5")) | |
| 302 | + self.assertEqual([c.move for c in child.variations], [chess.Move.from_uci("e7e5")]) | |
| 303 | + self.assertEqual(explain.suggestions(tree, child), [(chess.Move.from_uci("c7c5"), "Maia selten")]) | |
| 304 | + self.assertEqual([m for m, _ in explain.suggestions(tree, reply)], [chess.Move.from_uci("g1f3")]) | |
modified tests/test_export.py +12 −2
| @@ -106,9 +106,19 @@ class VariationTest(unittest.TestCase): | ||
| 106 | 106 | state = self.state() |
| 107 | 107 | loaded = savegames.from_pgn(savegames.to_pgn(state)) |
| 108 | 108 | # Kommentar ohne [%cal]; die Drohung kommt als Lichess-Gelb zurück (gelb bleibt gelb beim Zeichnen) |
| 109 | - (move, comment, shapes, children), = loaded.variations[4] | |
| 110 | - self.assertEqual((move, comment, children), state.variations[4][0][:2] + (state.variations[4][0][3],)) | |
| 109 | + (move, comment, shapes, children, name), = loaded.variations[4] | |
| 110 | + self.assertEqual((move, comment), state.variations[4][0][:2]) | |
| 111 | + self.assertEqual([c[:4] for c in children], state.variations[4][0][3]) | |
| 111 | 112 | self.assertEqual(shapes, ((chess.G8, chess.F6, "yellow"),)) |
| 113 | + self.assertEqual(name, "") | |
| 114 | + | |
| 115 | + def test_variation_name_survives_saving(self): | |
| 116 | + state = self.state() | |
| 117 | + move, comment, shapes, children = state.variations[4][0] | |
| 118 | + state.variations = {4: [(move, comment, shapes, children, "Zweispringerspiel")]} | |
| 119 | + text = savegames.to_pgn(state) | |
| 120 | + self.assertIn("( { Zweispringerspiel } 3... Nf6", text) | |
| 121 | + self.assertEqual(savegames.from_pgn(text).variations[4][0][4], "Zweispringerspiel") | |
| 112 | 122 | |
| 113 | 123 | def test_drawn_shapes_on_the_game_come_back_in_lichess_colors(self): |
| 114 | 124 | state = sample() |