Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

feat(hint): choose hint helper via split button

public

feat(hint): choose hint helper via split button

Maia 1500/2000/2500 (checked by Stockfish as before) or Stockfish
itself. Changing it re-prepares the hint for the current position.
Disabled in puzzles, where the hint is the solution.

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

modified schach/app.py +45 −6

@@ -24,7 +24,15 @@ from .online import OnlineMixin # noqa:
2424
 from .puzzles import PuzzleMixin  # noqa: E402
2525
 
2626
 APP_ID = "app.schach.Schach"
27
-HINT_ELO = 2000
27
+# Wer gibt den Hinweis? Maia schlägt menschliche Züge vor, Stockfish prüft sie (≤ 3 % schlechter);
28
+# "stockfish" nimmt direkt den besten Zug.
29
+HELPERS = {
30
+    "maia1500": ("Maia 1500", 1500),
31
+    "maia2000": ("Maia 2000", 2000),
32
+    "maia2500": ("Maia 2500", 2500),
33
+    "stockfish": ("Stockfish", None),
34
+}
35
+DEFAULT_HELPER = "maia2000"
2836
 OPPONENT_TEMPERATURE = 1.0  # menschliche Streuung; 0 = immer der wahrscheinlichste Zug
2937
 MIN_REPLY_SECONDS = 0.6
3038
 AUTOSAVE_DELAY_MS = 800
@@ -36,7 +44,7 @@ FEATURED_THEMES = [
3644
 SETTINGS_PATH = os.path.join(GLib.get_user_config_dir(), "schach", "settings.json")
3745
 DEFAULTS = {
3846
     "elo": 1200, "color": "white", "theme": "cburnett", "puzzle_difficulty": "normal",
39
-    "temperature": OPPONENT_TEMPERATURE, "scheme": "holz",
47
+    "temperature": OPPONENT_TEMPERATURE, "scheme": "holz", "hint_helper": DEFAULT_HELPER,
4048
 }
4149
 
4250
 
@@ -194,10 +202,20 @@ class Window(OnlineMixin, PuzzleMixin, A
194202
         self.mode_stack = Gtk.Stack(
195203
             transition_type=Gtk.StackTransitionType.CROSSFADE, hhomogeneous=False, interpolate_size=True,
196204
         )
205
+        helpers = Gio.Menu()
206
+        for key, (label, _elo) in HELPERS.items():
207
+            helpers.append(label, f"win.hint-helper::{key}")
208
+        helper_menu = Gio.Menu()
209
+        helper_menu.append_section("Hinweis von", helpers)
210
+        self.helper_menu = helper_menu
197211
         self.hint_content = Adw.ButtonContent(icon_name="dialog-information-symbolic", label="Hinweis")
198
-        self.hint_btn = Gtk.Button(child=self.hint_content)
212
+        self.hint_btn = Adw.SplitButton(
213
+            child=self.hint_content, menu_model=helper_menu, dropdown_tooltip="Wer hilft?",
214
+        )
199215
         self.hint_btn.set_action_name("win.hint")
200
-        self.mode_stack.add_named(self.hint_btn, "help")
216
+        self.help_box = Gtk.Box(spacing=6)
217
+        self.help_box.append(self.hint_btn)
218
+        self.mode_stack.add_named(self.help_box, "help")
201219
 
202220
         online_menu = Gio.Menu()
203221
         game = Gio.Menu()
@@ -316,6 +334,11 @@ class Window(OnlineMixin, PuzzleMixin, A
316334
         )
317335
         difficulty.connect("activate", self._set_puzzle_difficulty)
318336
         self.add_action(difficulty)
337
+        helper = Gio.SimpleAction.new_stateful(
338
+            "hint-helper", GLib.VariantType.new("s"), GLib.Variant.new_string(self._helper()),
339
+        )
340
+        helper.connect("activate", lambda _a, v: self.get_application().update_setting("hint_helper", v.get_string()))
341
+        self.add_action(helper)
319342
 
320343
         app = self.get_application()
321344
         app.set_accels_for_action("win.new-game", ["<Control>n"])
@@ -491,8 +514,9 @@ class Window(OnlineMixin, PuzzleMixin, A
491514
         self.hint_content.set_label("Zug zeigen" if self.hint_level == 1 else "Hinweis")
492515
         self.hint_btn.set_tooltip_text(
493516
             "Hinweis (H) – das Rätsel zählt dann nicht als gelöst" if self.mode == "puzzle"
494
-            else f"Hinweis von Maia {HINT_ELO} (H)"
517
+            else f"Hinweis von {HELPERS[self._helper()][0]} (H)"
495518
         )
519
+        self._action("hint-helper").set_enabled(self.mode == "maia")  # Rätsel: Hinweis = Lösung
496520
         user = self.get_application().lichess_user
497521
         self.online_content.set_label((user or {}).get("username") or "Lichess")
498522
         slot = "help" if hints else "online" if self.mode == "online" else "none"
@@ -742,7 +766,11 @@ class Window(OnlineMixin, PuzzleMixin, A
742766
             job = annotate.think_job(board, moves or [], thinking, snapshot_from_thread, hint_from_thread)
743767
             self.stockfish.submit(job, on_done)
744768
 
745
-        self.maia.submit(maia_candidates(board, HINT_ELO), on_candidates)
769
+        elo = HELPERS[self._helper()][1]
770
+        if elo is None:
771
+            on_candidates([], None)  # Stockfish: ohne Maia-Vorschläge gilt sein bester Zug
772
+        else:
773
+            self.maia.submit(maia_candidates(board, elo), on_candidates)
746774
 
747775
     def _on_snapshot(self, key, entry, final):
748776
         old = self.analyses.get(key)
@@ -1001,9 +1029,20 @@ class Window(OnlineMixin, PuzzleMixin, A
10011029
         self.view.flipped = not self.view.flipped
10021030
         self.view.queue_draw()
10031031
 
1032
+    def _helper(self):
1033
+        helper = self.settings.get("hint_helper", DEFAULT_HELPER)
1034
+        return helper if helper in HELPERS else DEFAULT_HELPER
1035
+
10041036
     def apply_setting(self, key, value):
10051037
         """Von den Einstellungen gerufen (für jedes Fenster)."""
10061038
         self.settings[key] = value
1039
+        if key == "hint_helper":
1040
+            self._action("hint-helper").set_state(GLib.Variant.new_string(value))
1041
+            if self.mode == "maia" and self._human_to_move():
1042
+                self._changed()  # Hinweis mit dem neuen Helfer neu vorbereiten
1043
+                self._refresh()
1044
+            else:
1045
+                self._refresh_chrome()
10071046
         if key == "theme":
10081047
             self.view.set_theme(value)
10091048
         elif key == "scheme":