feat(hints): Esc hides hint and threat, H/B shows them again for free
public
feat(hints): Esc hides hint and threat, H/B shows them again for free Esc first leaves the move list or demo as before; otherwise it hides a shown hint or threat. Pressing H or B brings back the same level without spending another duo help or counting twice in puzzles. Enter does not play a hidden hint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | c8db2dc3354a65a9c385daa0812a06f3f04f8f2b |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | f231aaa78d3b |
| Children | 176fb6d09729 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/app.py +39 −11
| @@ -56,7 +56,7 @@ SHORTCUTS = [ | ||
| 56 | 56 | ]), |
| 57 | 57 | ("Ansicht", [ |
| 58 | 58 | ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"), |
| 59 | - ("Zurück zur aktuellen Stellung", "Escape"), | |
| 59 | + ("Zurück zur aktuellen Stellung, Hinweis ausblenden", "Escape"), | |
| 60 | 60 | ]), |
| 61 | 61 | ("Spielstände", [ |
| 62 | 62 | ("Spielstand speichern", "<Control>s"), ("Spielstände öffnen", "<Control>o"), |
| @@ -142,6 +142,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 142 | 142 | self.explain_pending = False # dritte Hinweisstufe: Stockfish rechnet die Erklärung |
| 143 | 143 | self.explanation = None # (gen, {"demo": Demo, "label": "Warum Sf3?"}) – fertig für diese Stellung |
| 144 | 144 | self.threat_move = None # Bedrohung: Zug des Gegners, den er spielen würde, wäre er am Zug |
| 145 | + self.hints_hidden = False # Esc: Hinweis und Drohung ausgeblendet, H/B zeigt sie ohne Kosten wieder | |
| 145 | 146 | self.threat_level = 0 # 1 = bedrohtes Feld, 2 = auch die drohende Figur (2 ohne Zug: keine Drohung) |
| 146 | 147 | self.threat_pending = False |
| 147 | 148 | self.thinking = None # laufende Stockfish-Rechnung, während der Mensch nachdenkt |
| @@ -566,9 +567,10 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 566 | 567 | if not v.interactive: |
| 567 | 568 | v.selected = None |
| 568 | 569 | |
| 569 | - v.hint_from = self.hint_move.from_square if self.hint_move and self.hint_level >= 1 else None | |
| 570 | - v.hint_to = self.hint_move.to_square if self.hint_move and self.hint_level >= 2 else None | |
| 571 | - threat = self.threat_move if self._human_to_move() else None | |
| 570 | + shown = not self.hints_hidden | |
| 571 | + v.hint_from = self.hint_move.from_square if shown and self.hint_move and self.hint_level >= 1 else None | |
| 572 | + v.hint_to = self.hint_move.to_square if shown and self.hint_move and self.hint_level >= 2 else None | |
| 573 | + threat = self.threat_move if self._human_to_move() and shown else None | |
| 572 | 574 | v.threat_to = threat.to_square if threat and self.threat_level >= 1 else None |
| 573 | 575 | v.threat_from = threat.from_square if threat and self.threat_level >= 2 else None |
| 574 | 576 | v.hint_preview = self.hint_move if v.hint_to is not None else None |
| @@ -645,7 +647,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 645 | 647 | budget = self.mode != "duo" or self._duo_can_help() or self.hint_level == 1 |
| 646 | 648 | can_hint = ( |
| 647 | 649 | hints and budget and self._human_to_move() and not self.hint_pending and not self._browsing() |
| 648 | - and (self.hint_level < 2 or self._can_explain()) | |
| 650 | + and (self.hint_level < 2 or self._can_explain() or self.hints_hidden) | |
| 649 | 651 | ) |
| 650 | 652 | self.duo_btn.set_visible(self.mode == "duo") |
| 651 | 653 | self._action("duo-draw").set_enabled(self.mode == "duo" and not self._over()) |
| @@ -653,10 +655,11 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 653 | 655 | self._action("hint").set_enabled(can_hint) |
| 654 | 656 | self._action("play-hint").set_enabled( |
| 655 | 657 | hints and self.hint_level >= 2 and self.hint_move is not None and self._human_to_move() |
| 656 | - and not self._browsing() | |
| 658 | + and not self._browsing() and not self.hints_hidden | |
| 657 | 659 | ) |
| 658 | 660 | self.hint_btn.set_tooltip_text( |
| 659 | - "Hinweis (H) – das Rätsel zählt dann nicht als gelöst" if self.mode == "puzzle" | |
| 661 | + "Hinweis wieder zeigen (H)" if self.hints_hidden and self.hint_level | |
| 662 | + else "Hinweis (H) – das Rätsel zählt dann nicht als gelöst" if self.mode == "puzzle" | |
| 660 | 663 | else "Kurszug zeigen (H)" if self.mode == "opening" |
| 661 | 664 | else "Warum ist der Zug gut? (H)" if self.hint_level >= 2 |
| 662 | 665 | else f"Zug zeigen (H) – von {HELPERS[self._helper()][0]}" if self.hint_level == 1 |
| @@ -666,11 +669,14 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 666 | 669 | puzzle_open = self.mode != "puzzle" or (self.puzzle is not None and not self.puzzle["done"]) |
| 667 | 670 | threat_budget = self.mode != "duo" or self._duo_can_help() or self.threat_level == 1 |
| 668 | 671 | can_threat = ( |
| 669 | - hints and puzzle_open and threat_budget and self._human_to_move() and self.threat_level < 2 | |
| 672 | + hints and puzzle_open and threat_budget and self._human_to_move() | |
| 673 | + and (self.threat_level < 2 or self.hints_hidden) | |
| 670 | 674 | and not self.threat_pending and not self._browsing() |
| 671 | 675 | ) |
| 672 | 676 | self._action("threat").set_enabled(can_threat) |
| 673 | - if self.threat_level == 1: | |
| 677 | + if self.hints_hidden and self.threat_level: | |
| 678 | + tip = "Drohung wieder zeigen (B)" | |
| 679 | + elif self.threat_level == 1: | |
| 674 | 680 | tip = "Drohende Figur zeigen (B)" |
| 675 | 681 | elif self._threat_source() == "stockfish": |
| 676 | 682 | tip = "Drohung zeigen (B) – von Stockfish" |
| @@ -702,7 +708,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 702 | 708 | self.undo_btn.set_visible(self.mode in ("maia", "opening", "online", "duo")) |
| 703 | 709 | self._action("offer-draw").set_enabled(self._online_running() and len(self.board.move_stack) >= 2) |
| 704 | 710 | self._action("resign").set_enabled(self._online_running() and self.online_full is not None) |
| 705 | - self._action("end-browse").set_enabled(self.browse_ply is not None or self.demo is not None) | |
| 711 | + self._action("end-browse").set_enabled(self.browse_ply is not None or self.demo is not None | |
| 712 | + or self._hints_visible()) | |
| 706 | 713 | logged_in = self.get_application().lichess_user is not None |
| 707 | 714 | self._action("challenge").set_enabled(logged_in) |
| 708 | 715 | self._action("lichess-games").set_enabled(logged_in) |
| @@ -865,6 +872,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 865 | 872 | self.threat_move = None |
| 866 | 873 | self.threat_level = 0 |
| 867 | 874 | self.threat_pending = False |
| 875 | + self.hints_hidden = False | |
| 868 | 876 | if self.thinking is not None: |
| 869 | 877 | self.thinking.stop() |
| 870 | 878 | self.thinking = None |
| @@ -1035,6 +1043,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1035 | 1043 | def hint(self, *_): |
| 1036 | 1044 | if not self._human_to_move(): |
| 1037 | 1045 | return |
| 1046 | + if self._unhide_hints(self.hint_level): | |
| 1047 | + return | |
| 1038 | 1048 | if self.hint_level == 1: |
| 1039 | 1049 | self.hint_level = 2 |
| 1040 | 1050 | if self.mode == "opening": |
| @@ -1111,7 +1121,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1111 | 1121 | |
| 1112 | 1122 | def play_hint(self, *_): |
| 1113 | 1123 | """Enter: den Hinweiszug spielen, sobald Figur und Zielfeld gezeigt werden.""" |
| 1114 | - if self.hint_level >= 2 and self.hint_move is not None and not self._browsing(): | |
| 1124 | + if self.hint_level >= 2 and self.hint_move is not None and not self._browsing() and not self.hints_hidden: | |
| 1115 | 1125 | self._play_human(self.hint_move) |
| 1116 | 1126 | |
| 1117 | 1127 | # --- Bedrohung --------------------------------------------------------- |
| @@ -1134,6 +1144,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1134 | 1144 | return |
| 1135 | 1145 | if self.mode == "puzzle" and (self.puzzle is None or self.puzzle["done"]): |
| 1136 | 1146 | return |
| 1147 | + if self._unhide_hints(self.threat_level): | |
| 1148 | + return | |
| 1137 | 1149 | if self.mode == "duo" and self.threat_level == 0: |
| 1138 | 1150 | if not self._duo_can_help(): |
| 1139 | 1151 | return |
| @@ -1332,10 +1344,26 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1332 | 1344 | self.browse_ply = ply |
| 1333 | 1345 | self._refresh() |
| 1334 | 1346 | |
| 1347 | + def _hints_visible(self): | |
| 1348 | + return not self.hints_hidden and (self.hint_level > 0 or self.threat_level > 0) | |
| 1349 | + | |
| 1350 | + def _unhide_hints(self, level): | |
| 1351 | + """H oder B nach Esc: alles wieder einblenden, was schon gezeigt war (kostet nichts). | |
| 1352 | + True, wenn damit schon etwas zu sehen ist (``level`` > 0), sonst geht es normal weiter.""" | |
| 1353 | + if not self.hints_hidden: | |
| 1354 | + return False | |
| 1355 | + self.hints_hidden = False | |
| 1356 | + self._refresh() | |
| 1357 | + return level > 0 | |
| 1358 | + | |
| 1335 | 1359 | def _end_browse(self, *_): |
| 1336 | 1360 | if self.demo is not None: |
| 1337 | 1361 | return self._demo_end() |
| 1338 | 1362 | if self.browse_ply is None: |
| 1363 | + if self._hints_visible(): # Esc blendet Hinweis und Drohung aus | |
| 1364 | + self.hints_hidden = True | |
| 1365 | + self._refresh() | |
| 1366 | + return True | |
| 1339 | 1367 | return False |
| 1340 | 1368 | self.browse_ply = None |
| 1341 | 1369 | self._refresh() |