penguins
1.0.0
|
Go to the source code of this file.
Functions | |
bool | coords_same (Coords a, Coords b) |
Checks if two Coords pairs are equal. More... | |
const char * | strip_prefix (const char *str, const char *prefix) |
Returns a substring with the prefix removed if the given string starts with the prefix, otherwise returns NULL . More... | |
bool | parse_number (const char *str, long *result) |
Converts a string into a number, returns false if the string was invalid. More... | |
void * | memdup (const void *src, size_t size) |
A shorthand for malloc + memcpy (analogous to strdup ). More... | |
static void | random_init (void) |
static int | random_range (Rng *rng, int min, int max) |
Rng | init_stdlib_rng (void) |
Returns an RNG implementation based on the rand function from <stdlib.h> (and seeds it with srand ). More... | |
uint32_t | fnv32_hash (uint32_t state, const void *buf, size_t len) |
Computes the 32-bit FNV-1a hash of a given byte sequence. More... | |
Variables | |
const Coords | DIRECTION_TO_COORDS [DIRECTION_MAX] |
A table that maps Direction variants to relative Coords. More... | |
const Coords | NEIGHBOR_TO_COORDS [NEIGHBOR_MAX] |
A table that maps Neighbor variants to relative Coords. More... | |
const Neighbor | DIRECTION_TO_NEIGHBOR [DIRECTION_MAX] |
A table that maps Direction variants to corresponding Neighbor variants. More... | |
Checks if two Coords pairs are equal.
Definition at line 46 of file utils.h.
Referenced by PlayerPlacementController::on_mouse_move(), PlayerMovementController::on_mouse_move(), PlayerPlacementController::on_mouse_up(), PlayerMovementController::on_mouse_up(), CanvasPanel::paint_board(), CanvasPanel::paint_move_arrow(), and PlayerMovementController::paint_overlay().
const char* strip_prefix | ( | const char * | str, |
const char * | prefix | ||
) |
Returns a substring with the prefix removed if the given string starts with the prefix, otherwise returns NULL
.
Definition at line 46 of file utils.c.
Referenced by parse_arguments().
bool parse_number | ( | const char * | str, |
long * | result | ||
) |
Converts a string into a number, returns false
if the string was invalid.
A wrapper around the strtol
function, which, unlike atoi
, can reliably tell us whether an error has occurred, whereas atoi
simply returns zero, so there is no way to distinguish between an error or the string legitimately containing a zero.
[in] | str | |
[out] | result |
Definition at line 64 of file utils.c.
Referenced by parse_arguments().
void* memdup | ( | const void * | src, |
size_t | size | ||
) |
A shorthand for malloc
+ memcpy
(analogous to strdup
).
Definition at line 79 of file utils.c.
Referenced by Game::game_clone().
|
static |
Definition at line 87 of file utils.c.
Referenced by init_stdlib_rng().
|
static |
Definition at line 105 of file utils.c.
Referenced by init_stdlib_rng().
Rng init_stdlib_rng | ( | void | ) |
Returns an RNG implementation based on the rand
function from <stdlib.h>
(and seeds it with srand
).
Definition at line 123 of file utils.c.
Referenced by run_autonomous_mode(), and run_interactive_mode().
|
inline |
Computes the 32-bit FNV-1a hash of a given byte sequence.
This is a fast and simple hash function that shouldn't be used for anything serious. The invocations may be chained together to compute the hash of, say, a struct or an array by passing the returned value to the state
argument of the next call, however, the first call must use FNV32_INITIAL_STATE
as the value of state
.
Definition at line 151 of file utils.h.
Referenced by CanvasPanel::paint_tiles().
const Coords DIRECTION_TO_COORDS[DIRECTION_MAX] |
A table that maps Direction variants to relative Coords.
Definition at line 19 of file utils.c.
Referenced by BotState::bot_generate_all_moves_list(), BotState::bot_rate_move(), BotState::bot_rate_moves_list(), Game::calculate_penguin_possible_moves(), Game::count_obstructed_directions(), and PlayerMovementController::update_tile_attributes().
const Coords NEIGHBOR_TO_COORDS[NEIGHBOR_MAX] |
A table that maps Neighbor variants to relative Coords.
Definition at line 27 of file utils.c.
Referenced by BotState::bot_quick_junction_check(), and CanvasPanel::on_paint().
const Neighbor DIRECTION_TO_NEIGHBOR[DIRECTION_MAX] |
A table that maps Direction variants to corresponding Neighbor variants.
Definition at line 35 of file utils.c.
Referenced by BotState::bot_quick_junction_check().