feat(hints): square tags, arrow and ghost move for hint and threat
public
feat(hints): square tags, arrow and ghost move for hint and threat Stage 1 frames the one square subtly; stage 2 drops frame and glow for tags in a shared corner, an arrow under the pieces and the move shown half transparent. On captures the victim shifts right and the attacker left so both outlines stay readable (also in book preview). Enter plays the hint move once both squares are shown. Opening course: a piece-only hint counts half for repetition grading, since recalling the target square shows partial recall. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | c1ab5ff75ae785f994fbbdd147fd0b3a3d6896fa |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 11fdf5078ebc |
| Children | 2023f76409ee 45f827567c35 |
| Pushlog | by timo via ssh by timo via ssh |
modified README.md +3 −2
| @@ -6,10 +6,11 @@ Schlichtes GNOME-Schachprogramm (Python, | ||
| 6 | 6 | Im Dialog „Neue Partie“ auch mit Bedenkzeit (5, 10, 10+5, 15+10, 30 Minuten); die Uhr |
| 7 | 7 | startet mit dem ersten Zug. |
| 8 | 8 | - **Hinweis** (Taste `H`): Erster Druck lässt die Figur leuchten, zweiter Druck auch |
| 9 | - das Zielfeld. Wer hilft, steht im Pfeil-Menü daneben: Maia 1500, 2000 (Standard) oder | |
| 9 | + das Zielfeld – mit Pfeil, Feldnamen und dem Zug halb durchsichtig; `Enter` spielt ihn dann. | |
| 10 | + Im Eröffnungskurs zählt ein Hinweis, der nur die Figur zeigt, halb. Wer hilft, steht im Pfeil-Menü daneben: Maia 1500, 2000 (Standard) oder | |
| 10 | 11 | 2500 – jeweils von Stockfish geprüft – oder Stockfish selbst. |
| 11 | 12 | - **Drohung** (Taste `B`, Schwert): umgekehrt zum Hinweis. Erster Druck zeigt das |
| 12 | - bedrohte Feld (orange), zweiter die drohende Figur mit Pfeil. Die Drohung passt zum | |
| 13 | + bedrohte Feld (orange), zweiter die drohende Figur mit Pfeil und den Drohzug halb durchsichtig. Die Drohung passt zum | |
| 13 | 14 | Gegner: Maia in seiner Stärke schlägt vor, was er sehen würde, Stockfish prüft nur, ob es |
| 14 | 15 | wirklich etwas gewinnt. Im Pfeil-Menü neben dem Schwert lässt sich auf „Stockfish“ |
| 15 | 16 | (objektiv) umstellen. |
modified schach/app.py +18 −1
| @@ -50,7 +50,8 @@ AUTOSAVE_DELAY_MS = 800 | ||
| 50 | 50 | SHORTCUTS = [ |
| 51 | 51 | ("Partie", [ |
| 52 | 52 | ("Neue Partie", "<Control>n"), ("Zug zurücknehmen", "<Control>z BackSpace"), |
| 53 | - ("Hinweis", "h"), ("Drohung zeigen", "b"), ("Neues Rätsel", "r"), | |
| 53 | + ("Hinweis", "h"), ("Hinweiszug spielen (wenn beide Felder gezeigt)", "Return"), | |
| 54 | + ("Drohung zeigen", "b"), ("Neues Rätsel", "r"), | |
| 54 | 55 | ]), |
| 55 | 56 | ("Ansicht", [ |
| 56 | 57 | ("Brett drehen", "f"), ("Zugliste und Bewertung", "a"), |
| @@ -372,6 +373,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 372 | 373 | ("new-game", self._new_game_dialog), |
| 373 | 374 | ("undo", self.undo), |
| 374 | 375 | ("hint", self.hint), |
| 376 | + ("play-hint", self.play_hint), | |
| 375 | 377 | ("threat", self.threat), |
| 376 | 378 | ("flip", self.flip), |
| 377 | 379 | ("export", self._export_dialog), |
| @@ -426,6 +428,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 426 | 428 | app.set_accels_for_action("win.new-game", ["<Control>n"]) |
| 427 | 429 | app.set_accels_for_action("win.undo", ["<Control>z"]) |
| 428 | 430 | app.set_accels_for_action("win.hint", ["h"]) |
| 431 | + app.set_accels_for_action("win.play-hint", ["Return", "KP_Enter"]) | |
| 429 | 432 | app.set_accels_for_action("win.threat", ["b"]) |
| 430 | 433 | app.set_accels_for_action("win.flip", ["f"]) |
| 431 | 434 | app.set_accels_for_action("win.save-game", ["<Control>s"]) |
| @@ -543,6 +546,7 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 543 | 546 | v.selected = None |
| 544 | 547 | v.hint_from = v.hint_to = None |
| 545 | 548 | v.threat_from = v.threat_to = None |
| 549 | + v.hint_preview = v.threat_preview = None | |
| 546 | 550 | symbol = self.symbols.get(self.browse_ply) |
| 547 | 551 | v.badge = (shown.peek().to_square, symbol) if symbol and shown.move_stack else None |
| 548 | 552 | v.queue_draw() |
| @@ -561,6 +565,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 561 | 565 | threat = self.threat_move if self._human_to_move() else None |
| 562 | 566 | v.threat_to = threat.to_square if threat and self.threat_level >= 1 else None |
| 563 | 567 | v.threat_from = threat.from_square if threat and self.threat_level >= 2 else None |
| 568 | + v.hint_preview = self.hint_move if v.hint_to is not None else None | |
| 569 | + v.threat_preview = threat if v.threat_from is not None else None | |
| 564 | 570 | |
| 565 | 571 | v.badge = None |
| 566 | 572 | v.turn_marker = self.board.turn if self.mode == "duo" and not self._over() else None |
| @@ -639,6 +645,10 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 639 | 645 | self._action("duo-draw").set_enabled(self.mode == "duo" and not self._over()) |
| 640 | 646 | self._action("duo-resign").set_enabled(self.mode == "duo" and not self._over()) |
| 641 | 647 | self._action("hint").set_enabled(can_hint) |
| 648 | + self._action("play-hint").set_enabled( | |
| 649 | + hints and self.hint_level >= 2 and self.hint_move is not None and self._human_to_move() | |
| 650 | + and not self._browsing() | |
| 651 | + ) | |
| 642 | 652 | self.hint_btn.set_tooltip_text( |
| 643 | 653 | "Hinweis (H) – das Rätsel zählt dann nicht als gelöst" if self.mode == "puzzle" |
| 644 | 654 | else "Kurszug zeigen (H)" if self.mode == "opening" |
| @@ -1015,6 +1025,8 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1015 | 1025 | return |
| 1016 | 1026 | if self.hint_level == 1: |
| 1017 | 1027 | self.hint_level = 2 |
| 1028 | + if self.mode == "opening": | |
| 1029 | + self.course_stats["reveals"] += 1 # zweite Hälfte des Hinweises: auch das Zielfeld | |
| 1018 | 1030 | self._refresh() |
| 1019 | 1031 | return |
| 1020 | 1032 | if self.hint_level >= 2 or self.hint_pending: |
| @@ -1039,6 +1051,11 @@ class Window(OnlineMixin, PuzzleMixin, O | ||
| 1039 | 1051 | self.hint_pending = True # Vorausberechnung läuft noch; zeigt sich, sobald fertig |
| 1040 | 1052 | self._refresh() |
| 1041 | 1053 | |
| 1054 | + def play_hint(self, *_): | |
| 1055 | + """Enter: den Hinweiszug spielen, sobald Figur und Zielfeld gezeigt werden.""" | |
| 1056 | + if self.hint_level >= 2 and self.hint_move is not None and not self._browsing(): | |
| 1057 | + self._play_human(self.hint_move) | |
| 1058 | + | |
| 1042 | 1059 | # --- Bedrohung --------------------------------------------------------- |
| 1043 | 1060 | |
| 1044 | 1061 | def _threat_source(self): |
modified schach/diagram.py +96 −39
| @@ -157,6 +157,8 @@ class BoardPainter: | ||
| 157 | 157 | self.spotlight_via = None # bei „Se5“ nach „Sf3“ im Text: Zwischenfeld, zwei Pfeile |
| 158 | 158 | self.shapes = () # Pfeile und Felder aus Kurskommentaren: ((von, nach, Farbe), …) |
| 159 | 159 | self.preview = None # Zug, der halb durchsichtig gezeigt wird (Explorer: Maus über einer Zeile) |
| 160 | + self.hint_preview = None # Hinweiszug, sobald beide Felder gezeigt werden: ebenso halb durchsichtig | |
| 161 | + self.threat_preview = None # Drohzug des Gegners, sobald beide Felder gezeigt werden | |
| 160 | 162 | self.editing = False # Stellung aufbauen: keine geschlagenen Figuren anzeigen |
| 161 | 163 | self.eval_bar = None # Gewinnchance Weiß in Prozent: Balken links neben dem Brett |
| 162 | 164 | self._drag_sq = None |
| @@ -241,12 +243,16 @@ class BoardPainter: | ||
| 241 | 243 | king = self.board.king(self.board.turn) |
| 242 | 244 | if king is not None: |
| 243 | 245 | self._glow(cr, king, sq, CHECK, 0.85) |
| 244 | - for s in (self.hint_from, self.hint_to): | |
| 245 | - if s is not None: | |
| 246 | - self._mark(cr, s, sq, HINT) | |
| 247 | - for s in (self.threat_from, self.threat_to): | |
| 248 | - if s is not None: | |
| 249 | - self._mark(cr, s, sq, THREAT) | |
| 246 | + # Hinweis und Drohung, Stufe 1 (ein Feld): dezenter Rahmen, damit das Feld auffällt. | |
| 247 | + # Stufe 2 (beide Felder) ohne Rahmen – Feldnamen, Pfeil und halb durchsichtige Figur reichen. | |
| 248 | + for single, other, rgb in ((self.hint_from, self.hint_to, HINT), (self.threat_to, self.threat_from, THREAT)): | |
| 249 | + if single is not None and other is None: | |
| 250 | + self._frame(cr, single, sq, rgb) | |
| 251 | + # Pfeile von Hinweis und Drohung unter den Figuren: die halb durchsichtige Figur im Ziel bleibt klar | |
| 252 | + if self.hint_from is not None and self.hint_to is not None: | |
| 253 | + self._draw_arrow(cr, self.hint_from, self.hint_to, sq, HINT) | |
| 254 | + if self.threat_from is not None and self.threat_to is not None: | |
| 255 | + self._draw_arrow(cr, self.threat_from, self.threat_to, sq, THREAT) | |
| 250 | 256 | if self.spotlight is not None and self.spotlight_from is not None: |
| 251 | 257 | self._glow(cr, self.spotlight_from, sq, SPOTLIGHT, 0.8) |
| 252 | 258 | elif self.spotlight is not None: |
| @@ -274,19 +280,22 @@ class BoardPainter: | ||
| 274 | 280 | self._draw_piece(cr, piece, x + off, y + off, sq * scale) |
| 275 | 281 | cr.pop_group_to_source() |
| 276 | 282 | cr.paint_with_alpha(1 - p) |
| 277 | - ghosts = self._preview_ghosts() | |
| 283 | + ghosts, captured = self._preview_ghosts() | |
| 278 | 284 | faded = {src for _p, src, _dst in ghosts} |
| 285 | + nudge = sq * 0.14 # Schlagen: Opfer etwas nach rechts, Angreifer nach links – beide Umrisse bleiben lesbar | |
| 279 | 286 | for square, piece in self.board.piece_map().items(): |
| 280 | 287 | if (dragging and square == self._drag_sq) or square in hidden: |
| 281 | 288 | continue |
| 282 | 289 | x, y = self._square_origin(square) |
| 290 | + if square in captured: | |
| 291 | + x += nudge | |
| 283 | 292 | if square in faded: |
| 284 | 293 | self._draw_piece_alpha(cr, piece, x, y, sq, 0.35) |
| 285 | 294 | else: |
| 286 | 295 | self._draw_piece(cr, piece, x, y, sq) |
| 287 | 296 | for piece, _src, dst in ghosts: |
| 288 | 297 | x, y = self._square_origin(dst) |
| 289 | - self._draw_piece_alpha(cr, piece, x, y, sq, 0.6) | |
| 298 | + self._draw_piece_alpha(cr, piece, x - (nudge if dst in captured else 0), y, sq, 0.6) | |
| 290 | 299 | if anim: |
| 291 | 300 | p = anim["progress"] |
| 292 | 301 | for piece, src, dst in anim["movers"]: |
| @@ -294,8 +303,6 @@ class BoardPainter: | ||
| 294 | 303 | x1, y1 = self._square_origin(dst) |
| 295 | 304 | self._draw_piece(cr, piece, x0 + (x1 - x0) * p, y0 + (y1 - y0) * p, sq) |
| 296 | 305 | |
| 297 | - if self.threat_from is not None and self.threat_to is not None: | |
| 298 | - self._draw_arrow(cr, self.threat_from, self.threat_to, sq, THREAT) | |
| 299 | 306 | if self.spotlight is not None: |
| 300 | 307 | hops = [s for s in (self.spotlight_from, self.spotlight_via) if s is not None] + [self.spotlight] |
| 301 | 308 | for a, b in zip(hops, hops[1:]): |
| @@ -311,6 +318,10 @@ class BoardPainter: | ||
| 311 | 318 | self._square_tag(cr, hops[i], sq, SPOTLIGHT, hops[i - 1:i] + hops[i + 1:i + 2]) |
| 312 | 319 | if len(hops) == 1: |
| 313 | 320 | self._square_tag(cr, self.spotlight, sq, SPOTLIGHT) |
| 321 | + for squares, rgb in (((self.hint_from, self.hint_to), HINT), ((self.threat_from, self.threat_to), THREAT)): | |
| 322 | + shown = [s for s in squares if s is not None] | |
| 323 | + if shown: | |
| 324 | + self._square_tags(cr, shown, sq, rgb) | |
| 314 | 325 | |
| 315 | 326 | if self.strips: |
| 316 | 327 | if not self.editing: |
| @@ -342,16 +353,6 @@ class BoardPainter: | ||
| 342 | 353 | s = sq * 1.1 |
| 343 | 354 | self._draw_piece(cr, piece, px - s / 2, py - s / 2, s) |
| 344 | 355 | |
| 345 | - def _mark(self, cr, square, sq, rgb): | |
| 346 | - """Leuchtendes Feld mit Rahmen (Hinweis blau, Bedrohung orange).""" | |
| 347 | - self._glow(cr, square, sq, rgb, 0.9) | |
| 348 | - x, y = self._square_origin(square) | |
| 349 | - cr.set_source_rgba(*rgb, 0.95) | |
| 350 | - cr.set_line_width(max(sq * 0.05, 2)) | |
| 351 | - inset = sq * 0.04 | |
| 352 | - cr.rectangle(x + inset, y + inset, sq - 2 * inset, sq - 2 * inset) | |
| 353 | - cr.stroke() | |
| 354 | - | |
| 355 | 356 | def _square_tag(self, cr, square, sq, rgb, arrows=()): |
| 356 | 357 | """Zielfeld mit Namensschild („c4“): die Figur bleibt frei, der Name steht da. |
| 357 | 358 | |
| @@ -359,25 +360,59 @@ class BoardPainter: | ||
| 359 | 360 | Schneidet ein Pfeil dort, dann unten rechts, oben links, zuletzt unten links. |
| 360 | 361 | ``arrows``: Felder, zu denen oder von denen ein Pfeil an diesem Feld hängt. |
| 361 | 362 | """ |
| 363 | + free = self._tag_corners(cr, square, sq, arrows) | |
| 364 | + self._draw_tag(cr, square, sq, rgb, free[0] if free else 3) | |
| 365 | + | |
| 366 | + def _square_tags(self, cr, squares, sq, rgb): | |
| 367 | + """Namensschilder für ein Feld oder ein Feldpaar mit Pfeil (Hinweis, Drohung). | |
| 368 | + | |
| 369 | + Bei zwei Feldern sitzen beide Schilder möglichst in derselben Ecke – in der ersten, | |
| 370 | + die an keinem der beiden Felder den Pfeil schneidet; sonst wählt jedes Feld für sich. | |
| 371 | + """ | |
| 372 | + pair = len(squares) == 2 | |
| 373 | + free = [self._tag_corners(cr, s, sq, [o for o in squares if o != s] if pair else ()) for s in squares] | |
| 374 | + common = [c for c in free[0] if all(c in f for f in free[1:])] | |
| 375 | + for square, own in zip(squares, free): | |
| 376 | + corner = common[0] if common else own[0] if own else 3 | |
| 377 | + self._draw_tag(cr, square, sq, rgb, corner) | |
| 378 | + | |
| 379 | + def _tag_box(self, cr, square, sq, corner): | |
| 380 | + """(links, oben, Breite, Höhe, Text, Maße) des Schilds in Ecke ``corner`` (0 oben rechts … 3 unten links).""" | |
| 362 | 381 | x, y = self._square_origin(square) |
| 363 | 382 | text = chess.square_name(square) |
| 364 | 383 | cr.save() |
| 365 | 384 | cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) |
| 366 | 385 | cr.set_font_size(sq * 0.2) |
| 367 | 386 | ext = cr.text_extents(text) |
| 368 | - pad = sq * 0.05 | |
| 369 | - w, h = ext.width + 2 * pad, sq * 0.26 | |
| 387 | + cr.restore() | |
| 388 | + w, h = ext.width + 2 * sq * 0.05, sq * 0.26 | |
| 370 | 389 | inset = sq * 0.04 |
| 371 | 390 | corners = [(x + sq - w - inset, y + inset), (x + sq - w - inset, y + sq - h - inset), |
| 372 | 391 | (x + inset, y + inset), (x + inset, y + sq - h - inset)] |
| 392 | + left, top = corners[corner] | |
| 393 | + return left, top, w, h, text, ext | |
| 394 | + | |
| 395 | + def _tag_corners(self, cr, square, sq, arrows=()): | |
| 396 | + """Ecken (0 oben rechts, 1 unten rechts, 2 oben links, 3 unten links), die kein Pfeil schneidet.""" | |
| 397 | + x, y = self._square_origin(square) | |
| 373 | 398 | shaft = [] |
| 374 | 399 | for other in arrows: |
| 375 | 400 | fx, fy = self._square_origin(other) |
| 376 | 401 | shaft += [(x + sq / 2 + (fx - x) * t / 20, y + sq / 2 + (fy - y) * t / 20) for t in range(21)] |
| 377 | 402 | margin = sq * 0.06 # halber Schaft mit Rand |
| 378 | - left, top = next(((cx, cy) for cx, cy in corners | |
| 379 | - if not any(cx - margin < px < cx + w + margin and cy - margin < py < cy + h + margin | |
| 380 | - for px, py in shaft)), corners[-1]) | |
| 403 | + free = [] | |
| 404 | + for corner in range(4): | |
| 405 | + cx, cy, w, h, _text, _ext = self._tag_box(cr, square, sq, corner) | |
| 406 | + if not any(cx - margin < px < cx + w + margin and cy - margin < py < cy + h + margin for px, py in shaft): | |
| 407 | + free.append(corner) | |
| 408 | + return free | |
| 409 | + | |
| 410 | + def _draw_tag(self, cr, square, sq, rgb, corner): | |
| 411 | + left, top, w, h, text, ext = self._tag_box(cr, square, sq, corner) | |
| 412 | + pad = sq * 0.05 | |
| 413 | + cr.save() | |
| 414 | + cr.select_font_face("Sans", cairo.FONT_SLANT_NORMAL, cairo.FONT_WEIGHT_BOLD) | |
| 415 | + cr.set_font_size(sq * 0.2) | |
| 381 | 416 | r = h * 0.3 |
| 382 | 417 | cr.new_path() |
| 383 | 418 | cr.arc(left + w - r, top + r, r, -math.pi / 2, 0) |
| @@ -396,6 +431,16 @@ class BoardPainter: | ||
| 396 | 431 | cr.new_path() |
| 397 | 432 | cr.restore() |
| 398 | 433 | |
| 434 | + def _frame(self, cr, square, sq, rgb): | |
| 435 | + """Dünner, halb durchsichtiger Rahmen innen am Feldrand.""" | |
| 436 | + x, y = self._square_origin(square) | |
| 437 | + width = max(sq * 0.035, 1.5) | |
| 438 | + cr.new_path() | |
| 439 | + cr.set_source_rgba(*rgb, 0.7) | |
| 440 | + cr.set_line_width(width) | |
| 441 | + cr.rectangle(x + width / 2, y + width / 2, sq - width, sq - width) | |
| 442 | + cr.stroke() | |
| 443 | + | |
| 399 | 444 | def _ring(self, cr, square, sq, rgb): |
| 400 | 445 | """Markiertes Feld: Kreis wie bei Lichess.""" |
| 401 | 446 | x, y = self._square_origin(square) |
| @@ -459,21 +504,33 @@ class BoardPainter: | ||
| 459 | 504 | cr.paint() |
| 460 | 505 | cr.restore() |
| 461 | 506 | |
| 507 | + def _previews(self): | |
| 508 | + """[(Zug, Brett)], die halb durchsichtig gezeigt werden: Explorer-Zeile, Hinweis, Drohung.""" | |
| 509 | + shown = [(m, self.board) for m in dict.fromkeys((self.preview, self.hint_preview)) if m is not None] | |
| 510 | + if self.threat_preview is not None: | |
| 511 | + probe = self.board.copy(stack=False) # die Drohung spielt der Gegner, als wäre er am Zug | |
| 512 | + probe.push(chess.Move.null()) | |
| 513 | + shown.append((self.threat_preview, probe)) | |
| 514 | + return shown | |
| 515 | + | |
| 462 | 516 | def _preview_ghosts(self): |
| 463 | - """[(Figur, von, nach)] für den Vorschau-Zug, bei Rochade mit Turm.""" | |
| 464 | - move = self.preview | |
| 465 | - if move is None or move not in self.board.legal_moves: | |
| 466 | - return [] | |
| 467 | - piece = self.board.piece_at(move.from_square) | |
| 468 | - if move.promotion: | |
| 469 | - piece = chess.Piece(move.promotion, piece.color) | |
| 470 | - ghosts = [(piece, move.from_square, move.to_square)] | |
| 471 | - if self.board.is_castling(move): | |
| 472 | - rank = chess.square_rank(move.from_square) | |
| 473 | - kingside = self.board.is_kingside_castling(move) | |
| 474 | - ghosts.append((chess.Piece(chess.ROOK, piece.color), | |
| 475 | - chess.square(7 if kingside else 0, rank), chess.square(5 if kingside else 3, rank))) | |
| 476 | - return ghosts | |
| 517 | + """([(Figur, von, nach)], {Felder mit geschlagener Figur}) für die Vorschau-Züge, bei Rochade mit Turm.""" | |
| 518 | + ghosts, captured = [], set() | |
| 519 | + for move, board in self._previews(): | |
| 520 | + if move not in board.legal_moves: | |
| 521 | + continue | |
| 522 | + piece = board.piece_at(move.from_square) | |
| 523 | + if move.promotion: | |
| 524 | + piece = chess.Piece(move.promotion, piece.color) | |
| 525 | + ghosts.append((piece, move.from_square, move.to_square)) | |
| 526 | + if board.is_castling(move): | |
| 527 | + rank = chess.square_rank(move.from_square) | |
| 528 | + kingside = board.is_kingside_castling(move) | |
| 529 | + ghosts.append((chess.Piece(chess.ROOK, piece.color), | |
| 530 | + chess.square(7 if kingside else 0, rank), chess.square(5 if kingside else 3, rank))) | |
| 531 | + elif board.piece_at(move.to_square) is not None: # en passant: Opfer steht daneben, nichts überlappt | |
| 532 | + captured.add(move.to_square) | |
| 533 | + return ghosts, captured | |
| 477 | 534 | |
| 478 | 535 | def _draw_piece_alpha(self, cr, piece, x, y, size, alpha): |
| 479 | 536 | cr.push_group() |
modified schach/repetition.py +15 −4
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | Eine Linie ist ein Weg durch den Kurs vom Start bis zum Ende einer Variante. |
| 4 | 4 | Fehlerfrei und ohne Hinweis gespielt, wächst der Abstand bis zur nächsten |
| 5 | 5 | Wiederholung (1, 3, 7, 14 … Tage). Mit Fehler oder Hinweis ist sie sofort wieder |
| 6 | -fällig – kommt aber erst nach den anderen fälligen Linien dran. | |
| 6 | +fällig (ein Hinweis, der nur die Figur zeigt, zählt halb) – kommt aber erst nach den anderen fälligen Linien dran. | |
| 7 | 7 | |
| 8 | 8 | Reine Logik ohne GTK. Gespeichert wird als JSON, pro Kurs (Titel) und Linie |
| 9 | 9 | (UCI-Züge, mit Leerzeichen getrennt). |
| @@ -205,11 +205,22 @@ def played_line(course, moves, target=No | ||
| 205 | 205 | return matches[0] |
| 206 | 206 | |
| 207 | 207 | |
| 208 | +def hint_weight(hints, reveals): | |
| 209 | + """Gewicht der Hinweise: nur die Figur zählt halb, Figur und Zielfeld ganz. | |
| 210 | + | |
| 211 | + ``hints``: wie oft der Hinweis aufgerufen wurde, ``reveals``: wie oft davon auch das Zielfeld. | |
| 212 | + """ | |
| 213 | + return (hints + reveals) / 2 | |
| 214 | + | |
| 215 | + | |
| 208 | 216 | def grade(errors, hints, blunders): |
| 209 | - """Stufe wie bei Anki, aus dem Verlauf: kein Ausrutscher gut, einer schwer, mehr (oder ein Patzer) nochmal.""" | |
| 210 | - if blunders or errors + hints >= 2: | |
| 217 | + """Stufe wie bei Anki, aus dem Verlauf: kein Ausrutscher gut, einer schwer, mehr (oder ein Patzer) nochmal. | |
| 218 | + | |
| 219 | + ``hints`` darf halbe Hinweise enthalten (siehe ``hint_weight``): Hilfe gebraucht ist nie „gut“. | |
| 220 | + """ | |
| 221 | + if blunders or errors + hints > 1: | |
| 211 | 222 | return AGAIN |
| 212 | - if errors + hints == 1: | |
| 223 | + if errors + hints > 0: | |
| 213 | 224 | return HARD |
| 214 | 225 | return GOOD |
| 215 | 226 | |
modified schach/training.py +12 −7
| @@ -188,7 +188,7 @@ def square_at(label, x, y): | ||
| 188 | 188 | class OpeningMixin: |
| 189 | 189 | def _opening_init(self): |
| 190 | 190 | self.course = None |
| 191 | - self.course_stats = {"errors": 0, "hints": 0, "blunders": 0} | |
| 191 | + self.course_stats = {"errors": 0, "hints": 0, "reveals": 0, "blunders": 0} | |
| 192 | 192 | self.course_line = None # (id, Züge): die Linie, die heute dran ist (Lernkarte) |
| 193 | 193 | self.course_recorded = False |
| 194 | 194 | self.opening_busy = False # wartet auf Gegnerzug, Bewertung oder Zurücknahme |
| @@ -396,6 +396,7 @@ class OpeningMixin: | ||
| 396 | 396 | v.selected = None |
| 397 | 397 | v.badge = None |
| 398 | 398 | v.hint_from = v.hint_to = v.threat_from = v.threat_to = None |
| 399 | + v.hint_preview = v.threat_preview = None | |
| 399 | 400 | v.shapes = demo.steps[index][2] |
| 400 | 401 | v.queue_draw() |
| 401 | 402 | self._refresh_chrome() |
| @@ -502,7 +503,7 @@ class OpeningMixin: | ||
| 502 | 503 | self._leave_special() |
| 503 | 504 | self.mode = "opening" |
| 504 | 505 | self.course = course |
| 505 | - self.course_stats = {"errors": 0, "hints": 0, "blunders": 0} | |
| 506 | + self.course_stats = {"errors": 0, "hints": 0, "reveals": 0, "blunders": 0} | |
| 506 | 507 | self.course_line = progress().pick(course) |
| 507 | 508 | self.course_recorded = False |
| 508 | 509 | self.human = course.color |
| @@ -684,22 +685,26 @@ class OpeningMixin: | ||
| 684 | 685 | |
| 685 | 686 | def _opening_finished(self): |
| 686 | 687 | self.opening_busy = False |
| 687 | - errors, hints = self.course_stats["errors"], self.course_stats["hints"] | |
| 688 | + errors, hints, reveals = (self.course_stats[k] for k in ("errors", "hints", "reveals")) | |
| 689 | + halves = hints - reveals # Hinweise, bei denen nur die Figur gezeigt wurde | |
| 688 | 690 | if errors == 0 and hints == 0: |
| 689 | 691 | summary = "Ziel erreicht – ohne Fehlversuch und ohne Hinweis!" |
| 690 | 692 | else: |
| 691 | 693 | parts = [] |
| 692 | 694 | if errors: |
| 693 | - parts.append(f"{errors} Fehlversuch" + ("e" if errors > 1 else "")) | |
| 694 | - if hints: | |
| 695 | - parts.append(f"{hints} Hinweis" + ("e" if hints > 1 else "")) | |
| 695 | + parts.append(f"{errors} Fehlversuch" + ("en" if errors > 1 else "")) | |
| 696 | + if reveals: | |
| 697 | + parts.append(f"{reveals} Hinweis" + ("en" if reveals > 1 else "")) | |
| 698 | + if halves: | |
| 699 | + parts.append(f"{halves} halben Hinweis" + ("en" if halves > 1 else "")) | |
| 696 | 700 | summary = f"Ziel erreicht – mit {' und '.join(parts)}." |
| 697 | 701 | if not self.course_recorded and self.course is not None: |
| 698 | 702 | self.course_recorded = True # nach Zurücknehmen und erneutem Ende nicht doppelt zählen |
| 699 | 703 | target = self.course_line[0] if self.course_line else None |
| 700 | 704 | line = repetition.played_line(self.course, self.board.move_stack, target) |
| 701 | 705 | if line is not None: |
| 702 | - level = repetition.grade(errors, hints, self.course_stats["blunders"]) | |
| 706 | + level = repetition.grade(errors, repetition.hint_weight(hints, reveals), | |
| 707 | + self.course_stats["blunders"]) | |
| 703 | 708 | days = progress().record(self.course, line, level) |
| 704 | 709 | summary = f"{summary} {repetition.next_text(days, level)}" |
| 705 | 710 | self.final_text = summary |
modified tests/test_repetition.py +8 −0
| @@ -132,6 +132,14 @@ class ProgressTest(unittest.TestCase): | ||
| 132 | 132 | self.assertEqual(repetition.grade(1, 1, 0), repetition.AGAIN) |
| 133 | 133 | self.assertEqual(repetition.grade(1, 0, 1), repetition.AGAIN) # ein echter Patzer |
| 134 | 134 | |
| 135 | + def test_piece_only_hint_counts_half(self): | |
| 136 | + half = repetition.hint_weight(1, 0) # nur die Figur gezeigt | |
| 137 | + self.assertEqual(repetition.grade(0, half, 0), repetition.HARD) # Hilfe gebraucht ist nie „gut“ | |
| 138 | + self.assertEqual(repetition.grade(0, repetition.hint_weight(2, 0), 0), repetition.HARD) | |
| 139 | + self.assertEqual(repetition.grade(1, half, 0), repetition.AGAIN) | |
| 140 | + self.assertEqual(repetition.grade(0, repetition.hint_weight(1, 1), 0), repetition.HARD) | |
| 141 | + self.assertEqual(repetition.grade(0, repetition.hint_weight(2, 1), 0), repetition.AGAIN) | |
| 142 | + | |
| 135 | 143 | def test_hard_keeps_interval(self): |
| 136 | 144 | self.assertEqual(self.progress.record(self.course, self.main, repetition.HARD, at(0)), 1) # neu: morgen |
| 137 | 145 | self.progress.record(self.course, self.main, repetition.GOOD, at(1)) # 3 Tage |