Add bishop move gen tests
All checks were successful
Python tests (make) / test (push) Successful in 10s

This commit is contained in:
2025-08-17 19:12:16 -04:00
parent fb5e8bb0cb
commit af829f2208

View File

@@ -5,6 +5,7 @@ from test.chess_ffi import gen_white_pawn_push_promotions
from test.chess_ffi import gen_white_pawn_capture_promotions from test.chess_ffi import gen_white_pawn_capture_promotions
from test.chess_ffi import gen_white_pawn_captures from test.chess_ffi import gen_white_pawn_captures
from test.chess_ffi import gen_knight_moves from test.chess_ffi import gen_knight_moves
from test.chess_ffi import gen_bishop_moves
from test.chess_ffi import Move from test.chess_ffi import Move
from test.chess_ffi import Board from test.chess_ffi import Board
@@ -66,7 +67,58 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
def test_bishop_move_gen(self): def test_bishop_move_gen(self):
pass cases_bishop_all = [
("8/8/8/8/3B4/8/8/8 w - - 0 1", 13, "center d4: 13 moves"),
("8/8/8/8/B7/8/8/8 w - - 0 1", 7, "edge a4: 7 moves"),
("8/8/8/8/8/8/8/B7 w - - 0 1", 7, "corner a1: 7 moves"),
("8/8/8/8/8/8/8/1B6 w - - 0 1", 7, "b1: 7 moves"),
# all four diagonals blocked immediately by own pieces -> 0
("8/8/8/2P1P3/3B4/2P1P3/8/8 w - - 0 1", 0, "d4 with white pawns on c3,e3,c5,e5"),
# all four diagonals have a black piece on the first square -> 4 (all captures)
("8/8/8/2p1p3/3B4/2p1p3/8/8 w - - 0 1", 4, "d4 with black pawns on c3,e3,c5,e5"),
# mixed blockers: NE own on f6, SW capture on b2, SE capture on e3, NW open
("8/8/1p3P2/8/3B4/4p3/1p6/8 w - - 0 1", 6, ""),
]
captures_only = False
for fen, expected, msg in cases_bishop_all:
with self.subTest(msg=msg, fen=fen):
cnt = ctypes.c_int(0)
moves = (Move * MAX_MOVES)()
b = Board()
self.load_fen(fen, board=b)
gen_bishop_moves(b, moves, ctypes.byref(cnt), captures_only)
self.assertEqual(expected, cnt.value)
cases_bishop_caps = [
("8/8/8/8/3B4/8/8/8 w - - 0 1", 0, "no enemies to capture"),
# first squares on all rays are enemies → 4 captures
("8/8/8/2p1p3/3B4/2p1p3/8/8 w - - 0 1", 4, "adjacent caps on c3,e3,c5,e5"),
# enemies at far ends on each ray → still 4 captures (one per ray)
("7p/p7/8/8/3B4/8/8/p5p1 w - - 0 1", 4, "targets h8,a7,g1,a1"),
# mixed: only two rays have a capture
("8/8/1p3P2/8/3B4/2P5/5p2/8 w - - 0 1", 2, "d4: NW capture b6, SE capture f2; NE/SW blocked by own"),
]
captures_only = True
for fen, expected, msg in cases_bishop_caps:
with self.subTest(msg=msg, fen=fen):
cnt = ctypes.c_int(0)
moves = (Move * MAX_MOVES)()
b = Board()
self.load_fen(fen, board=b)
gen_bishop_moves(b, moves, ctypes.byref(cnt), captures_only)
self.assertEqual(expected, cnt.value)
def test_rook_move_gen(self): def test_rook_move_gen(self):