refactor(sicht): one table for what each activity shows
public
refactor(sicht): one table for what each activity shows Glyphs, evaluations, analysis board, hints and hint stage 3 per activity (sicht.SICHT: ja, nein, nach dem Ende) instead of seven scattered mode checks. No change in behaviour; test_sicht pins the previous rules. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 27e55313692267993b0065bae3abbaf5efc23417 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 4963ba2572c3 |
| Children | 33aa7e45b446 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/app.py +6 −6
| @@ -16,7 +16,7 @@ gi.require_version("Adw", "1") | ||
| 16 | 16 | gi.require_version("Graphene", "1.0") |
| 17 | 17 | from gi.repository import Adw, Gdk, Gio, GLib, GObject, Graphene, Gtk # noqa: E402 |
| 18 | 18 | |
| 19 | -from . import __version__, annotate, clipboard, energy, explain, lichess, notation, savegames, wdl, zustand # noqa: E402 | |
| 19 | +from . import __version__, annotate, clipboard, energy, explain, lichess, notation, savegames, sicht, wdl, zustand # noqa: E402 | |
| 20 | 20 | from .repetition import DEFAULT_RETENTION # noqa: E402 |
| 21 | 21 | from .board import BoardView, available_themes # noqa: E402 |
| 22 | 22 | from .endbar import EndBar # noqa: E402 |
| @@ -773,7 +773,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 773 | 773 | self.title.set_title(self.save_name or default_title) |
| 774 | 774 | self._refresh_players() |
| 775 | 775 | |
| 776 | - hints = self.mode in ("maia", "puzzle", "opening", "duo") | |
| 776 | + hints = sicht.allowed(self.mode, "hints") | |
| 777 | 777 | budget = self.mode != "duo" or self._duo_can_help() or self.hint_level == 1 |
| 778 | 778 | can_hint = ( |
| 779 | 779 | hints and budget and self._human_to_move() and not self.hint_pending and not self._browsing() |
| @@ -1281,7 +1281,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1281 | 1281 | |
| 1282 | 1282 | def _can_explain(self): |
| 1283 | 1283 | """Dritte Stufe: Erklärung zum gezeigten Zug (Kurse haben ihre eigenen „Warum?“-Fragen).""" |
| 1284 | - return (self.mode in ("maia", "duo", "puzzle") and self.hint_level >= 2 and self.hint_move is not None | |
| 1284 | + return (sicht.allowed(self.mode, "explain") and self.hint_level >= 2 and self.hint_move is not None | |
| 1285 | 1285 | and not self.explain_pending and self.demo is None) |
| 1286 | 1286 | |
| 1287 | 1287 | def _explain_hint(self): |
| @@ -1429,7 +1429,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1429 | 1429 | |
| 1430 | 1430 | def threat(self, *_): |
| 1431 | 1431 | """Erster Druck: bedrohtes Feld, zweiter: auch die drohende Figur.""" |
| 1432 | - if self.mode not in ("maia", "puzzle", "opening", "duo") or not self._human_to_move() or self._browsing(): | |
| 1432 | + if not sicht.allowed(self.mode, "hints") or not self._human_to_move() or self._browsing(): | |
| 1433 | 1433 | return |
| 1434 | 1434 | if self.mode == "puzzle" and (self.puzzle is None or self.puzzle["done"]): |
| 1435 | 1435 | return |
| @@ -1583,7 +1583,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1583 | 1583 | return False |
| 1584 | 1584 | |
| 1585 | 1585 | def _annotate(self, ply, move, before, retry=True): |
| 1586 | - if self.mode not in ("maia", "duo", "review"): | |
| 1586 | + if not sicht.allowed(self.mode, "symbols", self._over()): | |
| 1587 | 1587 | return |
| 1588 | 1588 | entry = self.analyses.get(annotate.key(before)) |
| 1589 | 1589 | symbol = annotate.classify_with(entry, before, move) |
| @@ -1665,7 +1665,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1665 | 1665 | |
| 1666 | 1666 | def _evals_locked(self): |
| 1667 | 1667 | """Während der Online-Partie bzw. vor der Lösung eines Rätsels keine Engine-Bewertung.""" |
| 1668 | - return self.mode == "online" or (self.mode == "puzzle" and not self._over()) | |
| 1668 | + return not sicht.allowed(self.mode, "evals", self._over()) | |
| 1669 | 1669 | |
| 1670 | 1670 | def _request_missing_evals(self): |
| 1671 | 1671 | if self._evals_locked(): |
added schach/sicht.py +32 −0
| @@ -0,0 +1,32 @@ | ||
| 1 | +"""Was je Aktivität zu sehen ist: eine Tabelle statt verstreuter Abfragen von ``mode``. | |
| 2 | + | |
| 3 | +Siehe roadmap/analysebrett.md, Stufe 6, und docs/adr/0002-aufdecken-statt-verbergen.md. Die | |
| 4 | +Tabelle sagt nur, was die Aktivität erlaubt; ob es gerade passt (Mensch am Zug, Hinweiszug | |
| 5 | +bekannt …), prüft der Aufrufer. | |
| 6 | +""" | |
| 7 | + | |
| 8 | +JA, NEIN, NACH_DEM_ENDE = "ja", "nein", "nach dem Ende" | |
| 9 | + | |
| 10 | +# symbols: Zugzeichen (?!, ?, ?? …) und „Warum nicht?“; evals: Bewertung und Gewinnchance-Balken; | |
| 11 | +# analysis: Analysebrett mit Partiebaum (sonst nur alte Stellungen ansehen); hints: Hinweis (H) und | |
| 12 | +# Bedrohung (B); explain: dritte Hinweisstufe („Warum?“). | |
| 13 | +SICHT = { | |
| 14 | + "maia": {"symbols": JA, "evals": JA, "analysis": JA, "hints": JA, "explain": JA}, | |
| 15 | + "review": {"symbols": JA, "evals": JA, "analysis": JA, "hints": NEIN, "explain": NEIN}, | |
| 16 | + "duo": {"symbols": JA, "evals": JA, "analysis": NEIN, "hints": JA, "explain": JA}, | |
| 17 | + "puzzle": {"symbols": NEIN, "evals": NACH_DEM_ENDE, "analysis": NEIN, "hints": JA, "explain": JA}, | |
| 18 | + "opening": {"symbols": NEIN, "evals": JA, "analysis": NEIN, "hints": JA, "explain": NEIN}, | |
| 19 | + "online": {"symbols": NEIN, "evals": NEIN, "analysis": NEIN, "hints": NEIN, "explain": NEIN}, | |
| 20 | + "setup": {"symbols": NEIN, "evals": JA, "analysis": NEIN, "hints": NEIN, "explain": NEIN}, | |
| 21 | +} | |
| 22 | + | |
| 23 | + | |
| 24 | +def allowed(mode, what, over=False): | |
| 25 | + """Erlaubt die Aktivität ``mode`` jetzt ``what``? ``over``: Partie bzw. Rätsel ist zu Ende.""" | |
| 26 | + rule = SICHT.get(mode, {}).get(what, NEIN) | |
| 27 | + return rule == JA or (rule == NACH_DEM_ENDE and over) | |
| 28 | + | |
| 29 | + | |
| 30 | +def modes(what): | |
| 31 | + """Aktivitäten, die ``what`` überhaupt erlauben (sofort oder nach dem Ende).""" | |
| 32 | + return tuple(mode for mode, rules in SICHT.items() if rules.get(what, NEIN) != NEIN) | |
modified schach/training.py +2 −3
| @@ -18,7 +18,7 @@ gi.require_version("Gtk", "4.0") | ||
| 18 | 18 | gi.require_version("Adw", "1") |
| 19 | 19 | from gi.repository import Adw, Gio, GLib, Gtk, Pango # noqa: E402 |
| 20 | 20 | |
| 21 | -from . import annotate, diagram, explain, notation, opening, repetition, savegames # noqa: E402 | |
| 21 | +from . import annotate, diagram, explain, notation, opening, repetition, savegames, sicht # noqa: E402 | |
| 22 | 22 | from .engines import maia_candidates # noqa: E402 |
| 23 | 23 | |
| 24 | 24 | OPPONENT_DELAY_MS = 650 |
| @@ -546,7 +546,6 @@ class OpeningMixin: | ||
| 546 | 546 | |
| 547 | 547 | # --- Analysebrett zur Partie ------------------------------------------- |
| 548 | 548 | |
| 549 | - ANALYSIS_MODES = ("maia", "review") # sonst bleibt es beim Blättern (Rätsel, Kurs, online, zu zweit) | |
| 550 | 549 | |
| 551 | 550 | def _game_tree(self): |
| 552 | 551 | """Baum zur Partie: die gespielten Züge sind die Hauptlinie (meta "played"), selbst gezogene |
| @@ -624,7 +623,7 @@ class OpeningMixin: | ||
| 624 | 623 | return depth - 1 |
| 625 | 624 | |
| 626 | 625 | def _analysis_allowed(self): |
| 627 | - return self.mode in self.ANALYSIS_MODES and bool(self.board.move_stack) | |
| 626 | + return sicht.allowed(self.mode, "analysis", self._over()) and bool(self.board.move_stack) | |
| 628 | 627 | |
| 629 | 628 | def _analysis_open(self, ply, show=True): |
| 630 | 629 | """Analysebrett an der Stellung nach Halbzug ``ply`` öffnen (auch aus einer anderen Vorführung). |
modified schach/zustand.py +4 −5
| @@ -8,12 +8,11 @@ jede Meldung einmal, mit ``SCHACH_STRENG | ||
| 8 | 8 | import logging |
| 9 | 9 | import os |
| 10 | 10 | |
| 11 | +from . import sicht | |
| 12 | + | |
| 11 | 13 | log = logging.getLogger("schach.zustand") |
| 12 | 14 | _reported = set() |
| 13 | 15 | |
| 14 | -ANALYSIS_MODES = ("maia", "review") | |
| 15 | -HINT_MODES = ("maia", "duo", "puzzle", "opening") | |
| 16 | - | |
| 17 | 16 | |
| 18 | 17 | def _analysis(win): |
| 19 | 18 | """Analysebrett zur Partie offen?""" |
| @@ -45,14 +44,14 @@ def violations(win): | ||
| 45 | 44 | found.append("Aufnahme und Wiedergabe zugleich") |
| 46 | 45 | if getattr(win, "replaying", False) and demo is None and mode != "setup": |
| 47 | 46 | found.append("Nachspielen ohne Analysebrett") # eine Vorführung darüber („Warum nicht?“) ist erlaubt |
| 48 | - if analysis and mode not in ANALYSIS_MODES: | |
| 47 | + if analysis and mode not in sicht.modes("analysis"): | |
| 49 | 48 | found.append(f"Analysebrett in Aktivität {mode!r}") |
| 50 | 49 | level = getattr(win, "hint_level", 0) |
| 51 | 50 | if level not in (0, 1, 2): |
| 52 | 51 | found.append(f"Hinweisstufe {level!r}") |
| 53 | 52 | if level and getattr(win, "hint_move", None) is None: |
| 54 | 53 | found.append(f"Hinweisstufe {level} ohne Hinweiszug") |
| 55 | - if level and mode not in HINT_MODES: | |
| 54 | + if level and mode not in sicht.modes("hints"): | |
| 56 | 55 | found.append(f"Hinweisstufe {level} in Aktivität {mode!r}") |
| 57 | 56 | if getattr(win, "explain_pending", False) and level != 2: |
| 58 | 57 | found.append(f"„Warum?“ wird gerechnet bei Hinweisstufe {level}") |
added tests/test_sicht.py +35 −0
| @@ -0,0 +1,35 @@ | ||
| 1 | +"""Tabelle, was je Aktivität zu sehen ist (schach/sicht.py).""" | |
| 2 | + | |
| 3 | +import unittest | |
| 4 | + | |
| 5 | +from schach import sicht | |
| 6 | + | |
| 7 | +MODES = ("maia", "review", "duo", "puzzle", "opening", "online", "setup") | |
| 8 | + | |
| 9 | + | |
| 10 | +class TableTest(unittest.TestCase): | |
| 11 | + def allowed(self, what, over=False): | |
| 12 | + return {mode for mode in MODES if sicht.allowed(mode, what, over)} | |
| 13 | + | |
| 14 | + def test_wie_vor_der_tabelle(self): | |
| 15 | + """Stand 24.11.2026: die Tabelle gibt die früher verstreuten Abfragen wieder.""" | |
| 16 | + self.assertEqual(self.allowed("symbols"), {"maia", "duo", "review"}) # _annotate | |
| 17 | + self.assertEqual(self.allowed("analysis"), {"maia", "review"}) # ANALYSIS_MODES | |
| 18 | + self.assertEqual(self.allowed("hints"), {"maia", "puzzle", "opening", "duo"}) | |
| 19 | + self.assertEqual(self.allowed("explain"), {"maia", "duo", "puzzle"}) # _can_explain | |
| 20 | + # _evals_locked: online immer, Rätsel bis zur Lösung | |
| 21 | + self.assertEqual(MODES_SET - self.allowed("evals"), {"online", "puzzle"}) | |
| 22 | + self.assertEqual(MODES_SET - self.allowed("evals", over=True), {"online"}) | |
| 23 | + | |
| 24 | + def test_unbekannt_ist_nein(self): | |
| 25 | + self.assertFalse(sicht.allowed("gibtsnicht", "hints")) | |
| 26 | + self.assertFalse(sicht.allowed("maia", "gibtsnicht")) | |
| 27 | + | |
| 28 | + def test_modes(self): | |
| 29 | + self.assertEqual(set(sicht.modes("evals")), MODES_SET - {"online"}) | |
| 30 | + | |
| 31 | + | |
| 32 | +MODES_SET = set(MODES) | |
| 33 | + | |
| 34 | +if __name__ == "__main__": | |
| 35 | + unittest.main() | |