#include "engine/moves.h" #include #include void moves_init(moves_t *moves) { return moves_init_wcapacity(moves, 16); } void moves_deinit(moves_t moves) { free(moves.moves); } void moves_init_wcapacity(moves_t *moves, u32 capacity) { moves->moves = malloc(capacity * sizeof(*moves)); moves->length = 0; moves->capacity = capacity; } moves_t moves_empty() { return (moves_t) { .moves = 0, .capacity = 0, .length = 0, }; } int min(int a, int b) { if (a > b) return b; return a; } void _add_move( moves_t* moves, square_t from, square_t to, struct add_move_params params ) { assert(moves->moves != 0); assert(from != to); if (moves->length + 1 >= moves->capacity) { moves->capacity += min(32, moves->capacity); moves->moves = realloc( moves->moves, moves->capacity * sizeof(*moves->moves) ); } moves->moves[moves->length++] = (move_t) { .from = from, .to = to, .flags = params.flags, }; }