Add board to fen function

This commit is contained in:
2025-08-25 20:10:38 -04:00
parent 633cdd2d7d
commit cbe16aba8a
3 changed files with 84 additions and 1 deletions

View File

@@ -62,6 +62,8 @@ FFI_SPEC = {
"load_fen": ((C.POINTER(Board), C.c_char_p), C.c_int),
"gen_pseudo_moves": ((C.POINTER(Board), C.POINTER(Move), C.c_bool), C.c_int),
"apply_move_on_copy": ((C.POINTER(Board), C.POINTER(Board), Move), C.c_bool),
"board_to_fen": ((C.POINTER(Board), C.c_char_p, C.c_size_t), None),
# AI Methods
"ai_find_best_move_with_window": ((C.POINTER(Board), C.c_int, C.c_int, C.POINTER(Move)), C.c_int)
}
@@ -151,7 +153,13 @@ class ChessFFI:
def load_fen(self, board, fen_string):
return self._c_load_fen(board, fen_string.encode("ascii"))
def board_to_fen(self, board, size=256):
buf = C.create_string_buffer(size)
self._c_board_to_fen(board, buf, size)
return buf.value.decode("ascii")
def gen_pseudo_moves(self, board, captures_only=False, cap=256):
buf = (Move * cap)()