@@ -48,6 +48,11 @@ def test_legal_moves(self):
4848 ('[FEN "W:B:WK2,28,31,44:B20,K50"]' , ["50x36" ], []),
4949 # King cannot jump adjacent pieces (28 and 33 have no empty square between)
5050 ('[FEN "W:B:W7,28,31,33:B20,30,K50"]' , [], ["50x50" ]),
51+ # King cannot hop over same piece twice during capture sequence
52+ # Black king on 49 should capture 38, 28, 24 (path: 49->32->19->30/35)
53+ # It should NOT capture 41 because to reach it after capturing 38,
54+ # and then continue to 28, would require crossing 41's square twice
55+ ('[FEN "W:B:W6,24,28,38,41:B13,K49"]' , ["49x30" , "49x35" ], []),
5156 ],
5257 )
5358 def test_king_capture_edge_cases (self , fen , valid_moves , invalid_moves ):
@@ -62,6 +67,36 @@ def test_king_capture_edge_cases(self, fen, valid_moves, invalid_moves):
6267 for move in invalid_moves :
6368 assert move not in move_strs , f"Invalid move { move } found in: { move_strs } "
6469
70+ def test_king_cannot_cross_captured_square (self ):
71+ """
72+ Test that king cannot cross a square where a piece was already captured.
73+
74+ FEN "W:B:W6,24,28,38,41:B13,K49" - Black king on 49
75+ Valid path: 49 -> capture 38 -> land on 32 -> capture 28 -> land on 19 -> capture 24 -> land on 30/35
76+ Invalid: capturing 41 then trying to capture 28 would cross the 41 square again
77+ """
78+ import numpy as np
79+
80+ board = Board .from_fen ('[FEN "W:B:W6,24,28,38,41:B13,K49"]' )
81+ legal_moves = board .legal_moves
82+
83+ # Should have exactly 2 moves (49x30 and 49x35)
84+ assert len (legal_moves ) == 2 , f"Expected 2 moves, got { len (legal_moves )} : { [str (m ) for m in legal_moves ]} "
85+
86+ # Both moves should capture exactly 3 pieces: 38, 28, 24
87+ for move in legal_moves :
88+ captured_1idx = sorted ([c + 1 for c in move .captured_list ])
89+ assert captured_1idx == [24 , 28 , 38 ], f"Expected captures [24, 28, 38], got { captured_1idx } "
90+
91+ # Piece on 41 should NOT be captured (it's on a different branch)
92+ test_board = Board .from_fen ('[FEN "W:B:W6,24,28,38,41:B13,K49"]' )
93+ test_board .push (legal_moves [0 ])
94+
95+ # Square 41 (0-indexed: 40) should still have a white piece
96+ assert test_board .position [40 ] == - 1 , "White piece on square 41 was incorrectly captured"
97+ # Square 6 (0-indexed: 5) should still have a white piece
98+ assert test_board .position [5 ] == - 1 , "White piece on square 6 was incorrectly captured"
99+
65100 def test_games_from_pdns (self ):
66101 import re
67102 with open (self .random_pdns , "r" ) as f :
0 commit comments