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>
| Changeset | ef0d7c95c61bd09a0da88cd5f25974fadb03882c |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 4cc840e11522 |
| Children | d62d22c199f7 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/app.py +45 −6
| @@ -24,7 +24,15 @@ from .online import OnlineMixin # noqa: | ||
| 24 | 24 | from .puzzles import PuzzleMixin # noqa: E402 |
| 25 | 25 | |
| 26 | 26 | 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" | |
| 28 | 36 | OPPONENT_TEMPERATURE = 1.0 # menschliche Streuung; 0 = immer der wahrscheinlichste Zug |
| 29 | 37 | MIN_REPLY_SECONDS = 0.6 |
| 30 | 38 | AUTOSAVE_DELAY_MS = 800 |
| @@ -36,7 +44,7 @@ FEATURED_THEMES = [ | ||
| 36 | 44 | SETTINGS_PATH = os.path.join(GLib.get_user_config_dir(), "schach", "settings.json") |
| 37 | 45 | DEFAULTS = { |
| 38 | 46 | "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, | |
| 40 | 48 | } |
| 41 | 49 | |
| 42 | 50 | |
| @@ -194,10 +202,20 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 194 | 202 | self.mode_stack = Gtk.Stack( |
| 195 | 203 | transition_type=Gtk.StackTransitionType.CROSSFADE, hhomogeneous=False, interpolate_size=True, |
| 196 | 204 | ) |
| 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 | |
| 197 | 211 | 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 | + ) | |
| 199 | 215 | 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") | |
| 201 | 219 | |
| 202 | 220 | online_menu = Gio.Menu() |
| 203 | 221 | game = Gio.Menu() |
| @@ -316,6 +334,11 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 316 | 334 | ) |
| 317 | 335 | difficulty.connect("activate", self._set_puzzle_difficulty) |
| 318 | 336 | 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) | |
| 319 | 342 | |
| 320 | 343 | app = self.get_application() |
| 321 | 344 | app.set_accels_for_action("win.new-game", ["<Control>n"]) |
| @@ -491,8 +514,9 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 491 | 514 | self.hint_content.set_label("Zug zeigen" if self.hint_level == 1 else "Hinweis") |
| 492 | 515 | self.hint_btn.set_tooltip_text( |
| 493 | 516 | "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)" | |
| 495 | 518 | ) |
| 519 | + self._action("hint-helper").set_enabled(self.mode == "maia") # Rätsel: Hinweis = Lösung | |
| 496 | 520 | user = self.get_application().lichess_user |
| 497 | 521 | self.online_content.set_label((user or {}).get("username") or "Lichess") |
| 498 | 522 | slot = "help" if hints else "online" if self.mode == "online" else "none" |
| @@ -742,7 +766,11 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 742 | 766 | job = annotate.think_job(board, moves or [], thinking, snapshot_from_thread, hint_from_thread) |
| 743 | 767 | self.stockfish.submit(job, on_done) |
| 744 | 768 | |
| 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) | |
| 746 | 774 | |
| 747 | 775 | def _on_snapshot(self, key, entry, final): |
| 748 | 776 | old = self.analyses.get(key) |
| @@ -1001,9 +1029,20 @@ class Window(OnlineMixin, PuzzleMixin, A | ||
| 1001 | 1029 | self.view.flipped = not self.view.flipped |
| 1002 | 1030 | self.view.queue_draw() |
| 1003 | 1031 | |
| 1032 | + def _helper(self): | |
| 1033 | + helper = self.settings.get("hint_helper", DEFAULT_HELPER) | |
| 1034 | + return helper if helper in HELPERS else DEFAULT_HELPER | |
| 1035 | + | |
| 1004 | 1036 | def apply_setting(self, key, value): |
| 1005 | 1037 | """Von den Einstellungen gerufen (für jedes Fenster).""" |
| 1006 | 1038 | 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() | |
| 1007 | 1046 | if key == "theme": |
| 1008 | 1047 | self.view.set_theme(value) |
| 1009 | 1048 | elif key == "scheme": |