#ifndef CHESSSTARS_ENGINE_H #define CHESSSTARS_ENGINE_H #include #define BOARD_SQUARES 64 #define MAX_HISTORY 120 #define PIECE_NONE 0 #define PIECE_PAWN 1 #define PIECE_KNIGHT 2 #define PIECE_BISHOP 3 #define PIECE_ROOK 4 #define PIECE_QUEEN 5 #define PIECE_KING 6 #define PIECE_COLOR_BIT 0x08 #define COLOR_WHITE 0 #define COLOR_BLACK 1 #define CASTLE_WK 0x01 #define CASTLE_WQ 0x02 #define CASTLE_BK 0x04 #define CASTLE_BQ 0x08 #define RULE_DISABLE_CASTLING 0x01 #define RULE_DISABLE_EN_PASSANT 0x02 #define RULE_IGNORE_CHECK 0x04 #define STATUS_ONGOING 0 #define STATUS_WHITE_WINS 1 #define STATUS_BLACK_WINS 2 #define STATUS_STALEMATE 3 typedef struct { uint8_t from; uint8_t to; uint8_t piece; uint8_t flags; uint8_t captured; uint8_t promo; uint8_t reserved0; uint8_t reserved1; } Move; #define MOVE_FLAG_CAPTURE 0x01 #define MOVE_FLAG_CASTLE_K 0x02 #define MOVE_FLAG_CASTLE_Q 0x04 #define MOVE_FLAG_EN_PASSANT 0x08 #define MOVE_FLAG_PROMOTION 0x10 typedef struct Engine Engine; typedef int (*ValidateFn)(Engine *e, Move m); typedef int (*LogFn)(const char *fmt, ...); struct Engine { uint32_t rule_flags; int32_t halfmove_clock; int32_t fullmove_number; uint8_t board[BOARD_SQUARES]; uint8_t turn; uint8_t castling_rights; int8_t ep_square; uint8_t variant; Move history[MAX_HISTORY]; ValidateFn validate_move; int32_t history_count; char game_id[40]; uint8_t _reserved0[28]; LogFn log_fn; }; #define ENGINE_LOG_SLOT 130 #define VARIANT_STANDARD 0 #define VARIANT_RELAXED 1 Engine *engine_new(int variant, const char *fen, uint32_t rule_flags, const char *game_id); void engine_free(Engine *e); int engine_add_move(Engine *e, Move m); int engine_is_legal(Engine *e, Move m); int engine_get_move_at(Engine *e, int32_t index, Move *out); int32_t engine_history_count(Engine *e); void engine_get_board(Engine *e, uint8_t out[BOARD_SQUARES]); int engine_turn(Engine *e); int engine_status(Engine *e); int engine_in_check(Engine *e); Move engine_bot_move(Engine *e, int depth); int engine_import_replay(Engine *e, const Move *moves, int32_t count); #endif