8-add-legal-move-filter (#16)
All checks were successful
Python tests (make) / test (push) Successful in 11s

works on #8

Reviewed-on: #16
Co-authored-by: Josh <josh@joshuaschuett.com>
Co-committed-by: Josh <josh@joshuaschuett.com>
This commit is contained in:
2025-08-19 19:56:44 +00:00
committed by Josh
parent e5a75c0737
commit 15b1a03928
4 changed files with 333 additions and 7 deletions

View File

@@ -91,10 +91,12 @@ gen_king_moves = _bind_opt("gen_king_moves", *PIECE_SIG)
ATTACKED_SIG = (C.POINTER(Board), C.c_int, C.c_int)
INCHECK_ARGS = (C.POINTER(Board), C.c_int)
ATTACKERS_TO = (C.POINTER(Board), C.c_int, C.c_int)
GEN_LEGAL_MOVES = (C.POINTER(Board), C.POINTER(Move))
square_attacked = _bind_opt("square_attacked", ATTACKED_SIG, C.c_bool)
in_check = _bind_opt("in_check", INCHECK_ARGS, C.c_bool)
attackers_to = _bind_opt("attackers_to", ATTACKERS_TO, C.c_uint64)
get_legal_moves = _bind_opt("get_legal_moves", GEN_LEGAL_MOVES, C.c_int)
# Attack cache tables.
@@ -126,6 +128,10 @@ def gen_moves(board, captures_only=False, cap=256):
return buf, n
def gen_legal_moves(board, out):
return int(get_legal_moves(C.byref(board), out))
def is_square_attacked(board, sq, by):
return bool(square_attacked(C.byref(board), int(sq), int(by)))