207 BotState*
self,
int penguins_count,
Coords* penguins,
int* moves_count
218 bool (*check)(
int x,
int y,
void* data),
219 void (*mark)(
int x,
int y,
void* data),
220 FillSpan* (*alloc_stack)(
size_t capacity,
void* data),
void flood_fill(int x, int y, bool(*check)(int x, int y, void *data), void(*mark)(int x, int y, void *data), FillSpan *(*alloc_stack)(size_t capacity, void *data), void *data)
An implementation of flood fill using the span filling algorithm.
BotPlacementStrategy
Values of BotParameters::placement_strategy.
@ BOT_PLACEMENT_MOST_FISH
Pick the tiles with the most fish in the vicinity.
@ BOT_PLACEMENT_SMART
The standard "smart" algorithm, see bot_compute_placement for its description.
@ BOT_PLACEMENT_RANDOM
Pick a random tile for placement.
@ BOT_PLACEMENT_FIRST_POSSIBLE
Pick the first possible tile (first tile in the first row).
BotMovementStrategy
Values of BotParameters::movement_strategy.
@ BOT_MOVEMENT_SMART
The standard "smart" algorithm, see bot_compute_move for its description.
@ BOT_MOVEMENT_RANDOM
Pick a random move.
@ BOT_MOVEMENT_FIRST_POSSIBLE
Pick the first possible move (also known as the "dumb" algorithm).
The core of the unified game logic library, contains the Game struct.
Movement phase functions.
A penguin -> target pair.
Various parameters for the bot algorithm.
BotPlacementStrategy placement_strategy
BOT_PLACEMENT_SMART by default.
int max_move_length
The maximum number of tiles allowed for bot's moves, must be positive.
int recursion_limit
The maximum recursion depth, must be positive. Zero means no recursion.
void init_bot_parameters(BotParameters *self)
Initializes all fields of the given BotParameters to default values.
BotMovementStrategy movement_strategy
BOT_MOVEMENT_SMART by default.
int junction_check_recursion_limit
The maximum recursion depth at which junction checks are performed.
int placement_scan_area
An area surrounding the placement tile which bot_rate_placement considers.
Contains temporary data created during the evaluation of bot's moves.
bool bot_compute_placement(BotState *self, Coords *out_target)
Computes the best placement for the current player given the current game state.
PossibleSteps * possible_steps
struct BotState * substate
The link to the next recursive substate. Substates are allocated on demand by bot_enter_substate.
void bot_state_free(BotState *self)
Recursively destroys a BotState and its substates (similarly to game_free).
Rng * rng
Just the Rng, nothing special.
const BotParameters * params
Shouldn't be changed while the bot is running (hence marked as const).
int bot_rate_move(BotState *self, BotMove move)
The heart of the bot, assigns a score to the given move according to its usefulness.
BotMove * bot_generate_all_moves_list(BotState *self, int penguins_count, Coords *penguins, int *moves_count)
Creates a list with all the possible moves (as penguin -> target pairs) of the provided penguins.
short * bot_flood_fill_reset_grid(BotState *self, short **fill_grid, size_t *fill_grid_cap)
Allocates a grid for use in bot_flood_fill_count_fish and fills it with zeroes.
bool bot_quick_junction_check(BotState *self, Coords coords)
A precondition for junction checks to know if a more expensive flood fill test is necessary.
int * bot_rate_moves_list(BotState *self, int moves_count, BotMove *moves_list)
Applies bot_rate_move to every move in the provided list and returns a pointer to the list of scores.
volatile bool cancelled
Can be set to true from another thread to cancel the move evaluation.
Game * game
May be modified during the move evaluation, but once the job is done the Game will be returned to its...
int depth
The recursion depth of the current state, starts at 0 for the base state and increases in substates.
BotState * bot_state_new(const BotParameters *params, Game *game, Rng *rng)
Constructs a BotState (similarly game_new).
int bot_flood_fill_count_fish(BotState *self, short *grid, Coords start, short marker_value)
Counts all fish accessible within an enclosed area starting at the given point using the flood fill a...
bool bot_compute_move(BotState *self, Coords *out_penguin, Coords *out_target)
Computes the best move for the current player given the current game state.
size_t possible_steps_cap
BotState * bot_enter_substate(BotState *self)
Allocates BotState::substate if necessary and returns it.
int bot_rate_placement(BotState *self, Coords penguin)
Assigns a score to the placement at the given coordinates.
A pair of 2D coordinates, used for addressing the Game::board_grid.
Used internally by flood_fill.
The central struct of the application, holds the game data and settings.
Exists purely to wrap an array of the numbers of steps in every possible Direction.
A wrapper around random number generators.