Add python c binding class interface (#29)
All checks were successful
Python tests (make) / test (push) Successful in 14s

Reviewed-on: #29
Co-authored-by: Josh <josh@joshuaschuett.com>
Co-committed-by: Josh <josh@joshuaschuett.com>
This commit is contained in:
2025-08-22 19:28:03 +00:00
committed by Josh
parent c27977bef8
commit 6005741b10
10 changed files with 338 additions and 357 deletions

View File

@@ -1,13 +1,8 @@
import ctypes
from test.base import ChessLibTestBase
from test.chess_ffi import get_attackers_to
from test.chess_ffi import is_square_attacked
from test.chess_ffi import is_in_check
from test.chess_ffi import sq
from test.chess_ffi import Board
from test.chess_ffi import BLACK
from test.chess_ffi import WHITE
from test.chess_ffi import draw_bb
from binding.python_c_ffi import Board
from binding.python_c_ffi import sq
from binding.python_c_ffi import BLACK
from binding.python_c_ffi import WHITE
class TestAttackers(ChessLibTestBase):
@@ -50,8 +45,8 @@ class TestAttackers(ChessLibTestBase):
for fen, sq_str, by, expected, msg in cases:
with self.subTest(msg=msg, fen=fen, sq=sq_str, by=by):
b = Board()
self.load_fen(fen, board=b)
got = bool(is_square_attacked(b, sq(sq_str), by))
self.chess_ffi.load_fen(b, fen)
got = self.chess_ffi.square_attacked(b, sq(sq_str), by)
self.assertEqual(expected, got, msg)
@@ -81,8 +76,8 @@ class TestAttackers(ChessLibTestBase):
for fen, side, expected, msg in cases:
with self.subTest(msg=msg, fen=fen, side=side):
b = Board()
self.load_fen(fen, board=b)
actual = bool(is_in_check(b, side))
self.chess_ffi.load_fen(b, fen)
actual = self.chess_ffi.in_check(b, side)
self.assertEqual(expected, actual, msg)
@@ -132,7 +127,6 @@ class TestAttackers(ChessLibTestBase):
for fen, sq_str, by, expected_cnt, msg in cases:
with self.subTest(msg=msg, fen=fen, sq=sq_str, by=by):
b = Board()
self.load_fen(fen, board=b)
mask = get_attackers_to(b, sq(sq_str), by)
self.chess_ffi.load_fen(b, fen)
mask = self.chess_ffi.attackers_to(b, sq(sq_str), by)
self.assertEqual(expected_cnt, int(mask).bit_count())