feat(analyse): hovering a move in a comment shows the piece it really means
public
feat(analyse): hovering a move in a comment shows the piece it really means Comments remember which move they name. Hovering "De2" draws the queen translucent on her start square, even after she moved on, with the arrow starting there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 1dc0bd680d3ca968a70c9cce461ce707ec2c06e4 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | fb758839f099 |
| Children | 824427b62eed |
| Pushlog | by timo via ssh by timo via ssh |
modified roadmap/analysebrett.md +4 −1
| @@ -145,7 +145,10 @@ Was übrig bleibt, bestimmt die Pfeile an den Gabelungen und die Tiefe. | ||
| 145 | 145 | findet … besser“ (oder „ähnlich gut“). Eine Linie läuft weiter, solange |
| 146 | 146 | Schach gegeben wird. Neuer Erkenner: „Der Springer geht dem Angriff g4 aus |
| 147 | 147 | dem Weg.“ Das Ergebnis nennt die Figuren statt nur den Saldo: „Du gibst |
| 148 | - einen Springer und bekommst einen Bauern.“ | |
| 148 | + einen Springer und bekommst einen Bauern.“ Jeder Kommentar merkt sich, | |
| 149 | + welche Figur ein genannter Zug meint. Beim Hovern über „De2“ erscheint | |
| 150 | + die Dame halb durchsichtig auf ihrem Startfeld, auch wenn sie schon | |
| 151 | + weitergezogen ist, und der Pfeil führt von dort aus. | |
| 149 | 152 | 3. **Zugliste und Einstiege:** Klick und Knopf „Aufs Analysebrett“, dazu Menü |
| 150 | 153 | und Taste. `review` und das Blättern in der Zugliste gehen im Analysebrett |
| 151 | 154 | auf. |
modified schach/diagram.py +4 −0
| @@ -156,6 +156,7 @@ class BoardPainter: | ||
| 156 | 156 | self.spotlight = None # Feld, das gerade im Text gezeigt wird (Maus über „e4“) |
| 157 | 157 | self.spotlight_from = None # bei „Ld3“: der Läufer, der dorthin ziehen kann (Pfeil) |
| 158 | 158 | self.spotlight_via = None # bei „Se5“ nach „Sf3“ im Text: Zwischenfeld, zwei Pfeile |
| 159 | + self.spotlight_ghost = None # Figur, die halb durchsichtig auf spotlight_from steht (schon weggezogen) | |
| 159 | 160 | self.imagined = False # gedachte Zukunft („Warum?“-Vorführung): Brett leicht getönt |
| 160 | 161 | self.branches = () # Gabelung in der Vorführung: ((von, nach, rgb, Schild), …), anklickbar |
| 161 | 162 | self._branch_hits = [] # (links, oben, rechts, unten, Index) der gezeichneten Schilder |
| @@ -301,6 +302,9 @@ class BoardPainter: | ||
| 301 | 302 | self._draw_piece_alpha(cr, piece, x, y, sq, 0.35) |
| 302 | 303 | else: |
| 303 | 304 | self._draw_piece(cr, piece, x, y, sq) |
| 305 | + if self.spotlight is not None and self.spotlight_ghost is not None and self.spotlight_from is not None: | |
| 306 | + x, y = self._square_origin(self.spotlight_from) | |
| 307 | + self._draw_piece_alpha(cr, self.spotlight_ghost, x, y, sq, 0.45) | |
| 304 | 308 | for piece, _src, dst in ghosts: |
| 305 | 309 | x, y = self._square_origin(dst) |
| 306 | 310 | self._draw_piece_alpha(cr, piece, x - (nudge if dst in captured else 0), y, sq, 0.6) |
modified schach/explain.py +20 −6
| @@ -308,7 +308,8 @@ class Tree: | ||
| 308 | 308 | |
| 309 | 309 | ``meta[node]``: "label" (Schild an der Gabelung), "maia" (Wahrscheinlichkeit oder None), |
| 310 | 310 | "best" (beste Verteidigung), "wp" (eigene Gewinnchance nach dem Zug), "mate" (führt zum Matt), |
| 311 | - "shapes" (Pfeile und Kreise), "pv" (Stockfishs Fortsetzung, nur beim Aufbau). | |
| 311 | + "shapes" (Pfeile und Kreise), "pv" (Stockfishs Fortsetzung, nur beim Aufbau), "refs" (im Text | |
| 312 | + genannte Züge als (Ziel, Figurenart, Start, Figur): „De2“ meint die Dame, die von dort kommt). | |
| 312 | 313 | """ |
| 313 | 314 | game: chess.pgn.Game |
| 314 | 315 | meta: dict = dataclasses.field(default_factory=dict) |
| @@ -331,6 +332,9 @@ class Tree: | ||
| 331 | 332 | def shapes(self, node): |
| 332 | 333 | return self.meta.get(node, {}).get("shapes", ()) |
| 333 | 334 | |
| 335 | + def refs(self, node): | |
| 336 | + return self.meta.get(node, {}).get("refs", ()) | |
| 337 | + | |
| 334 | 338 | def label(self, node): |
| 335 | 339 | return self.meta.get(node, {}).get("label", "") |
| 336 | 340 | |
| @@ -524,6 +528,14 @@ def comment(tree, threat=None, only_move | ||
| 524 | 528 | before = node.parent.board() |
| 525 | 529 | sentences, shapes = describe(before, node.move, hero) |
| 526 | 530 | meta = tree.info(node) |
| 531 | + refs = [] | |
| 532 | + | |
| 533 | + def say(position, move): | |
| 534 | + """Zug für den Text; merkt sich, welcher echte Zug gemeint ist (für das Hovern).""" | |
| 535 | + piece = position.piece_at(move.from_square) | |
| 536 | + if piece is not None: | |
| 537 | + refs.append((move.to_square, piece.piece_type, move.from_square, piece)) | |
| 538 | + return _san(position, move) | |
| 527 | 539 | if node is first and node.board().is_checkmate(): |
| 528 | 540 | pass # Matt sagt alles |
| 529 | 541 | elif node is first and before.turn == hero: |
| @@ -531,16 +543,16 @@ def comment(tree, threat=None, only_move | ||
| 531 | 543 | replayed = threat is not None and any(r.move == threat and tree.meta.get(r, {}).get("best") |
| 532 | 544 | for r in replies) |
| 533 | 545 | if threat is not None and not replayed: |
| 534 | - sentences.append(f"Das wehrt die Drohung {_san(board_null(board), threat)} ab.") | |
| 546 | + sentences.append(f"Das wehrt die Drohung {say(board_null(board), threat)} ab.") | |
| 535 | 547 | shapes.append((threat.from_square, threat.to_square, "threat")) # was gedroht hätte |
| 536 | 548 | if only_move: |
| 537 | 549 | sentences.append("Alle anderen Züge sind deutlich schlechter.") |
| 538 | 550 | if better is not None: |
| 539 | - name = _san(board, better) | |
| 551 | + name = say(board, better) | |
| 540 | 552 | sentences.append(f"Besser war {name}." if why is None else f"Besser war {name}: {why}") |
| 541 | 553 | elif rival is not None: |
| 542 | 554 | other, gap = rival |
| 543 | - sentences.append(f"Stockfish findet {_san(board, other)} " | |
| 555 | + sentences.append(f"Stockfish findet {say(board, other)} " | |
| 544 | 556 | + ("ähnlich gut." if gap < RIVAL_GAP else "besser.")) |
| 545 | 557 | elif not sentences: |
| 546 | 558 | sentences.append("Stockfish hält das für den besten Zug.") |
| @@ -559,7 +571,7 @@ def comment(tree, threat=None, only_move | ||
| 559 | 571 | sentences.append(f"Die beste Antwort von {COLOR[before.turn]}.") |
| 560 | 572 | mate = mate_threat(before) |
| 561 | 573 | if mate is not None: |
| 562 | - name = _san(board_null(before), mate) | |
| 574 | + name = say(board_null(before), mate) | |
| 563 | 575 | after = node.board() |
| 564 | 576 | if mate in after.legal_moves and _mates(after, mate): |
| 565 | 577 | sentences.append(f"Das übersieht {name}.") |
| @@ -572,7 +584,7 @@ def comment(tree, threat=None, only_move | ||
| 572 | 584 | if before.turn == hero and not after.is_check(): |
| 573 | 585 | mate = mate_threat(after) |
| 574 | 586 | if mate is not None: |
| 575 | - sentences.append(f"Du drohst {_san(board_null(after), mate)}.") | |
| 587 | + sentences.append(f"Du drohst {say(board_null(after), mate)}.") | |
| 576 | 588 | shapes.append((mate.from_square, mate.to_square, "hint")) |
| 577 | 589 | if not node.variations and not after.is_checkmate(): |
| 578 | 590 | gain = material(after, hero) - start |
| @@ -584,6 +596,8 @@ def comment(tree, threat=None, only_move | ||
| 584 | 596 | sentences.append(f"Ergebnis: {result}{good}.") |
| 585 | 597 | node.comment = " ".join(sentences) |
| 586 | 598 | meta["shapes"] = tuple(shapes) |
| 599 | + if refs: | |
| 600 | + meta["refs"] = tuple(refs) | |
| 587 | 601 | return tree |
| 588 | 602 | |
| 589 | 603 | |
modified schach/training.py +20 −4
| @@ -274,15 +274,31 @@ class OpeningMixin: | ||
| 274 | 274 | |
| 275 | 275 | def _coach_spotlight(self, hit): |
| 276 | 276 | """``hit`` aus square_at: Feld leuchtet; bei „Ld3“ ein Pfeil vom Läufer, bei „Se5“ evtl. über „Sf3“.""" |
| 277 | - square = origin = via = None | |
| 277 | + square = origin = via = ghost = None | |
| 278 | 278 | if hit is not None: |
| 279 | 279 | square, piece, extra = hit |
| 280 | - origin, via = route(self.view.board, self.coach_label.get_layout().get_text(), piece, extra, square) | |
| 280 | + known = self._demo_ref(square, piece, extra) | |
| 281 | + if known is not None: # der Kommentar weiß, welche Figur gemeint ist, auch wenn sie schon weg ist | |
| 282 | + origin, ghost = known | |
| 283 | + if self.view.board.piece_at(origin) == ghost: | |
| 284 | + ghost = None | |
| 285 | + else: | |
| 286 | + origin, via = route(self.view.board, self.coach_label.get_layout().get_text(), piece, extra, square) | |
| 281 | 287 | v = self.view |
| 282 | - if (v.spotlight, v.spotlight_from, v.spotlight_via) != (square, origin, via): | |
| 283 | - v.spotlight, v.spotlight_from, v.spotlight_via = square, origin, via | |
| 288 | + if (v.spotlight, v.spotlight_from, v.spotlight_via, v.spotlight_ghost) != (square, origin, via, ghost): | |
| 289 | + v.spotlight, v.spotlight_from, v.spotlight_via, v.spotlight_ghost = square, origin, via, ghost | |
| 284 | 290 | v.queue_draw() |
| 285 | 291 | |
| 292 | + def _demo_ref(self, square, piece, extra): | |
| 293 | + """Im Kommentar der Vorführung genannter Zug nach ``square``: (Startfeld, Figur) oder None.""" | |
| 294 | + if self.demo is None or self.demo["busy"]: | |
| 295 | + return None | |
| 296 | + kind = PIECE_TYPES.get(piece) | |
| 297 | + for target, ref_kind, start, ref_piece in self.demo["tree"].refs(self.demo["node"]): | |
| 298 | + if target == square and ref_kind == kind and (not extra or extra in chess.square_name(start)): | |
| 299 | + return start, ref_piece | |
| 300 | + return None | |
| 301 | + | |
| 286 | 302 | def _coach(self, markup, ply=None, replace=False, shapes=(), demos=()): |
| 287 | 303 | """Neue Rückmeldung zur Stellung nach Halbzug ``ply`` (Standard: aktuelle Stellung). |
| 288 | 304 | |
modified tests/test_explain.py +3 −0
| @@ -229,6 +229,9 @@ class ExplainJobTest(unittest.TestCase): | ||
| 229 | 229 | finally: |
| 230 | 230 | engine.quit() |
| 231 | 231 | self.assertIn("Stockfish findet Sxd5 besser.", tree.first().comment) |
| 232 | + # beim Hovern über „Sxd5“ zeigt der Pfeil vom Springer auf c3, auch wenn er schon gezogen hat | |
| 233 | + self.assertIn((chess.D5, chess.KNIGHT, chess.C3, chess.Piece(chess.KNIGHT, chess.WHITE)), | |
| 234 | + tree.refs(tree.first())) | |
| 232 | 235 | |
| 233 | 236 | |
| 234 | 237 | class TradeTextTest(unittest.TestCase): |