Public repository: timo / schach

Reader

Ein aufgeräumtes Schach-Programm für GNOME

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>
Changeset4e35d08bc0a144f5d96d33f3cacf77e070c082b9
Author (claimed)Timo Stolz <timo.stolz@nullachtvierzehn.de>,
Parents489813b33743
Children72385b734fb5
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):
104104
     """Von wo zieht die Figur aus „Ld3“ nach ``square``? None, wenn sie schon dort steht oder keine kann.
105105
 
106106
     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.
107108
     """
108109
     kind = PIECE_TYPES.get(piece)
109110
     if kind is None:
@@ -121,6 +122,16 @@ def mover(board, piece, extra, square):
121122
             if extra and extra not in name:
122123
                 continue
123124
             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]
124135
     return None
125136
 
126137
 

modified tests/test_opening.py +4 −0

@@ -221,6 +221,10 @@ class SquareNamesTest(unittest.TestCase)
221221
         self.assertEqual(mover(board, "S", "", chess.F6), chess.G8)  # auch für die andere Seite
222222
         self.assertIsNone(mover(board, "S", "", chess.F3))  # steht schon dort
223223
         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
224228
 
225229
     def test_mark_squares_leaves_tags_alone(self):
226230
         from schach.training import mark_squares