Add python c binding class interface #29
@@ -1,18 +1,7 @@
|
||||
import ctypes
|
||||
from binding.python_c_ffi import Board
|
||||
from binding.python_c_ffi import Move
|
||||
from test.base import ChessLibTestBase
|
||||
from test.chess_ffi import gen_white_pawn_quiet_pushes
|
||||
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_captures
|
||||
from test.chess_ffi import gen_knight_moves
|
||||
from test.chess_ffi import gen_bishop_moves
|
||||
from test.chess_ffi import gen_rook_moves
|
||||
from test.chess_ffi import gen_queen_moves
|
||||
from test.chess_ffi import gen_king_moves
|
||||
from test.chess_ffi import Move
|
||||
from test.chess_ffi import Board
|
||||
from test.chess_ffi import BLACK
|
||||
from test.chess_ffi import WHITE
|
||||
|
||||
|
||||
MAX_MOVES = 256
|
||||
@@ -26,12 +15,12 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
moves = (Move * MAX_MOVES)()
|
||||
b = Board()
|
||||
|
||||
self.load_fen(fen, board=b)
|
||||
self.chess_ffi.load_fen(b , fen)
|
||||
if captures_only is not None:
|
||||
move_function(b, moves, ctypes.byref(cnt), captures_only)
|
||||
move_function(b, moves, cnt, captures_only)
|
||||
else:
|
||||
# Account for pawn move gen.
|
||||
move_function(b, moves, ctypes.byref(cnt))
|
||||
move_function(b, moves, cnt)
|
||||
self.assertEqual(expected, cnt.value)
|
||||
|
||||
|
||||
@@ -61,8 +50,8 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
("8/8/8/8/3N4/1P3p2/4P3/8 w - - 0 1", 1, "d4 with f3 black (1 cap), b3/e2 white (not capturable)"),
|
||||
("8/8/2p1p3/1p3p2/3N4/1p3p2/2p1p3/8 w - - 0 1", 8, "d4 with all 8 targets black: 8 captures"),
|
||||
]
|
||||
self.run_subtests(all_move_types, gen_knight_moves, captures_only=False)
|
||||
self.run_subtests(captures_only, gen_knight_moves, captures_only=True)
|
||||
self.run_subtests(all_move_types, self.chess_ffi._c_gen_knight_moves, captures_only=False)
|
||||
self.run_subtests(captures_only, self.chess_ffi._c_gen_knight_moves, captures_only=True)
|
||||
|
||||
|
||||
def test_bishop_move_gen(self):
|
||||
@@ -94,8 +83,8 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
# 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"),
|
||||
]
|
||||
self.run_subtests(cases_bishop_all, gen_bishop_moves, captures_only=False)
|
||||
self.run_subtests(cases_bishop_caps, gen_bishop_moves, captures_only=True)
|
||||
self.run_subtests(cases_bishop_all, self.chess_ffi._c_gen_bishop_moves, captures_only=False)
|
||||
self.run_subtests(cases_bishop_caps, self.chess_ffi._c_gen_bishop_moves, captures_only=True)
|
||||
|
||||
|
||||
def test_rook_move_gen(self):
|
||||
@@ -133,8 +122,8 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
("8/8/8/3P4/p2RP3/8/8/3p4 w - - 0 1", 2,
|
||||
"own on d5,e4; captures on a4 and d1"),
|
||||
]
|
||||
self.run_subtests(cases_rook_all, gen_rook_moves, captures_only=False)
|
||||
self.run_subtests(cases_rook_caps, gen_rook_moves, captures_only=True)
|
||||
self.run_subtests(cases_rook_all, self.chess_ffi._c_gen_rook_moves, captures_only=False)
|
||||
self.run_subtests(cases_rook_caps, self.chess_ffi._c_gen_rook_moves, captures_only=True)
|
||||
|
||||
|
||||
def test_queen_move_gen(self):
|
||||
@@ -173,8 +162,8 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
# mixed: captures on two diagonals only
|
||||
("7p/p7/8/8/3Q4/8/8/p5p1 w - - 0 1", 4, "diagonal targets a1,a7,g1,h8 (4 captures)"),
|
||||
]
|
||||
self.run_subtests(cases_queen_all, gen_queen_moves, captures_only=False)
|
||||
self.run_subtests(cases_queen_caps, gen_queen_moves, captures_only=True)
|
||||
self.run_subtests(cases_queen_all, self.chess_ffi._c_gen_queen_moves, captures_only=False)
|
||||
self.run_subtests(cases_queen_caps, self.chess_ffi._c_gen_queen_moves, captures_only=True)
|
||||
|
||||
|
||||
def test_king_move_gen(self):
|
||||
@@ -232,11 +221,10 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
# blocked queenside (d8 occupied) → only O-O available
|
||||
("r2bk2r/8/8/8/8/8/8/8 b kq - 0 1", 5, "d8 blocked; only king-side castle"),
|
||||
]
|
||||
|
||||
self.run_subtests(cases_king_all, gen_king_moves, captures_only=False)
|
||||
self.run_subtests(cases_king_castle_white, gen_king_moves, captures_only=False)
|
||||
self.run_subtests(cases_king_caps, gen_king_moves, captures_only=True)
|
||||
self.run_subtests(cases_king_castle_black, gen_king_moves, captures_only=False)
|
||||
self.run_subtests(cases_king_all, self.chess_ffi._c_gen_king_moves, captures_only=False)
|
||||
self.run_subtests(cases_king_castle_white, self.chess_ffi._c_gen_king_moves, captures_only=False)
|
||||
self.run_subtests(cases_king_caps, self.chess_ffi._c_gen_king_moves, captures_only=True)
|
||||
self.run_subtests(cases_king_castle_black, self.chess_ffi._c_gen_king_moves, captures_only=False)
|
||||
|
||||
|
||||
def test_quiet_pawn_pushes_white(self):
|
||||
@@ -248,7 +236,7 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
# Although legal move, we have a separate function that calculates this move type.
|
||||
("8/9P/8/8/8/8/8/8 w - - 0 1", 0, "no promotion push"),
|
||||
]
|
||||
self.run_subtests(cases, gen_white_pawn_quiet_pushes)
|
||||
self.run_subtests(cases, self.chess_ffi._c_gen_white_pawn_quiet_pushes)
|
||||
|
||||
|
||||
def test_quiet_pawn_promotions_white(self):
|
||||
@@ -258,7 +246,7 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
("7n/7P/8/8/8/8/8/8 w - - 0 1", 0, "blocked by enemy"),
|
||||
("7N/7P/8/8/8/8/8/8 w - - 0 1", 0, "blocked by friendly"),
|
||||
]
|
||||
self.run_subtests(cases, gen_white_pawn_push_promotions)
|
||||
self.run_subtests(cases, self.chess_ffi._c_gen_white_pawn_push_promotions)
|
||||
|
||||
|
||||
def test_capture_pawn_promotions_white(self):
|
||||
@@ -267,7 +255,7 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
("5n1n/6P1/8/8/8/8/8/8 w - - 0 1", 8, "two captures"),
|
||||
("8/7P/8/8/8/8/8/8 w - - 0 1", 0, "no capture"),
|
||||
]
|
||||
self.run_subtests(cases, gen_white_pawn_capture_promotions)
|
||||
self.run_subtests(cases, self.chess_ffi._c_gen_white_pawn_capture_promotions)
|
||||
|
||||
|
||||
def test_capture_pawn_white(self):
|
||||
@@ -283,4 +271,4 @@ class TestPseudoMoveGeneration(ChessLibTestBase):
|
||||
("8/8/5n2/3pP3/8/8/8/8 w - d6 0 1", 2, "EP e5xd6 and normal e5xf6"),
|
||||
("8/8/8/3p4/8/4P3/8/8 w - d6 0 1", 0, "EP square present but no white pawn can take"),
|
||||
]
|
||||
self.run_subtests(cases, gen_white_pawn_captures)
|
||||
self.run_subtests(cases, self.chess_ffi._c_gen_white_pawn_captures)
|
||||
Reference in New Issue
Block a user