diff --git a/test/test_attack_to.py b/test/test_attack_to.py index 3d5aa3b..a235916 100644 --- a/test/test_attack_to.py +++ b/test/test_attack_to.py @@ -87,8 +87,45 @@ class TestAttackers(ChessLibTestBase): def test_attackers_to_popcount(self): cases = [ - # Bishop on d4, adjacent enemies on each ray → 4 attackers - ("8/8/8/2p1p3/3B4/2p1p3/8/8 w - - 0 1", "d4", BLACK, 2, "adjacent enemies on c5,e5,c3,e3"), + # Pawns (original correction): only c5 & e5 attack d4 + ("8/8/8/2p1p3/3B4/2p1p3/8/8 w - - 0 1", "d4", BLACK, 2, "black pawns c5,e5 attack d4; c3,e3 do not"), + + # 0 attackers on empty board + ("8/8/8/8/8/8/8/8 w - - 0 1", "d4", WHITE, 0, "no pieces -> no attackers"), + + # Knights: b5 and f5 both hit d4 + ("8/8/8/1n3n2/8/8/8/8 w - - 0 1", "d4", BLACK, 2, "two black knights b5,f5 attack d4"), + + # White pawns from below (c3,e3) attack d4 + ("8/8/8/8/8/2P1P3/8/8 w - - 0 1", "d4", WHITE, 2, "white pawns c3,e3 attack d4"), + + # Rooks on the file: d8 and d1 both see d4 + ("3R4/8/8/8/8/8/8/3R4 w - - 0 1", "d4", WHITE, 2, "two white rooks d8,d1 attack d4"), + + # Bishops on diagonals: b6 and f2 see d4 + ("8/8/1B6/8/8/8/5B2/8 w - - 0 1", "d4", WHITE, 2, "two white bishops b6,f2 attack d4"), + + # Mixed sliders: Ba7 and Rd1 both hit d4 + ("8/B7/8/8/8/8/8/3R4 w - - 0 1", "d4", WHITE, 2, "white bishop a7 and rook d1 attack d4"), + + # Rook blocked by own pawn -> no attack up the file + ("8/8/8/8/8/8/3P4/3R4 w - - 0 1", "d4", WHITE, 0, "rook d1 blocked by own pawn d2"), + + # Two queens (different lines) both attack d4 + ("3Q4/8/8/8/7Q/8/8/8 w - - 0 1", "d4", WHITE, 2, "queens d8 (file) and h4 (rank) attack d4"), + + # Double-check-style: Qe2 and Nc7 attack e8 + ("4k3/2N5/8/8/8/8/4Q3/4K3 w - - 0 1", "e8", WHITE, 2, "white queen e2 and knight c7 attack e8"), + + # Blocked slider by enemy pawn: rook e4 cannot reach e8 + ("4k3/4p3/8/8/4R3/8/8/4K3 w - - 0 1", "e8", WHITE, 0, "white rook e4 blocked by black pawn e7"), + + # Three independent attackers to e4: Nf6, Be3 (from b1 path), Re1 + ("8/8/5N2/8/8/8/8/1B2R3 w - - 0 1", "e4", WHITE, 3, "knight f6, bishop b1 path, rook e1 all attack e4"), + + # King adjacency (illegal in play but functionally one attacker) + # We need to ensure that the legal move filter catches this case. + ("8/8/8/8/8/8/4k3/4K3 w - - 0 1", "e1", BLACK, 1, "black king e2 attacks e1"), ] for fen, sq_str, by, expected_cnt, msg in cases: