fix(coach): arrow for plan moves like Lf4 behind own pawns
public
fix(coach): arrow for plan moves like Lf4 behind own pawns Fall back to the unique piece that reaches the square on an empty board; bishops resolve by square colour. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| Changeset | 4e35d08bc0a144f5d96d33f3cacf77e070c082b9 |
|---|---|
| Author (claimed) | Timo Stolz <timo.stolz@nullachtvierzehn.de>, |
| Parents | 489813b33743 |
| Children | 72385b734fb5 |
| Pushlog | by timo via ssh by timo via ssh |
modified schach/training.py +11 −0
| @@ -104,6 +104,7 @@ def mover(board, piece, extra, square): | ||
| 104 | 104 | """Von wo zieht die Figur aus „Ld3“ nach ``square``? None, wenn sie schon dort steht oder keine kann. |
| 105 | 105 | |
| 106 | 106 | Zuerst die Seite am Zug, dann die andere (Kommentare sprechen über beide). |
| 107 | + Kann gerade keine dorthin, zählt der Plan: bei Läufern entscheidet die Feldfarbe. | |
| 107 | 108 | """ |
| 108 | 109 | kind = PIECE_TYPES.get(piece) |
| 109 | 110 | if kind is None: |
| @@ -121,6 +122,16 @@ def mover(board, piece, extra, square): | ||
| 121 | 122 | if extra and extra not in name: |
| 122 | 123 | continue |
| 123 | 124 | return move.from_square |
| 125 | + # Plan statt Zug („Lf4“ im Aufbau, der Weg ist noch zu): die eine Figur, die es auf leerem Brett könnte | |
| 126 | + for color in (board.turn, not board.turn): | |
| 127 | + found = [] | |
| 128 | + for origin in board.pieces(kind, color): | |
| 129 | + empty = chess.BaseBoard(None) | |
| 130 | + empty.set_piece_at(origin, chess.Piece(kind, color)) | |
| 131 | + if empty.is_attacked_by(color, square) and (not extra or extra in chess.square_name(origin)): | |
| 132 | + found.append(origin) | |
| 133 | + if len(found) == 1: | |
| 134 | + return found[0] | |
| 124 | 135 | return None |
| 125 | 136 | |
| 126 | 137 | |
modified tests/test_opening.py +4 −0
| @@ -221,6 +221,10 @@ class SquareNamesTest(unittest.TestCase) | ||
| 221 | 221 | self.assertEqual(mover(board, "S", "", chess.F6), chess.G8) # auch für die andere Seite |
| 222 | 222 | self.assertIsNone(mover(board, "S", "", chess.F3)) # steht schon dort |
| 223 | 223 | self.assertIsNone(mover(board, None, "", chess.E4)) # nur ein Feld |
| 224 | + start = chess.Board() | |
| 225 | + self.assertEqual(mover(start, "L", "", chess.F4), chess.C1) # Aufbau-Plan: der schwarzfeldrige Läufer | |
| 226 | + self.assertEqual(mover(start, "S", "", chess.D2), chess.B1) # nur einer passt | |
| 227 | + self.assertIsNone(mover(start, "T", "", chess.D1)) # zwei Türme könnten: lieber kein Pfeil | |
| 224 | 228 | |
| 225 | 229 | def test_mark_squares_leaves_tags_alone(self): |
| 226 | 230 | from schach.training import mark_squares |