Add legal move filter with test
This commit is contained in:
@@ -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)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user