47 return a.
x == b.
x && a.
y == b.
y;
72 #define UNUSED(var) ((void)(var))
84 #define ALWAYS_INLINE __attribute__((always_inline))
85 #elif defined(_MSC_VER)
86 #define ALWAYS_INLINE __forceinline
92 #define free_and_clear(ptr) (free((ptr)), (ptr) = NULL)
95 #define sizeof_array(ptr) (sizeof((ptr)) / sizeof(*(ptr)))
99 #define my_max(x, y) (((x) > (y)) ? (x) : (y))
101 #define my_min(x, y) (((x) < (y)) ? (x) : (y))
105 #define set_bit(num, bit) ((num) | (bit))
106 #define clear_bit(num, bit) ((num) & ~(bit))
107 #define toggle_bit(num, bit) ((num) ^ (bit))
108 #define change_bit(num, bit, val) (((num) & ~(bit)) | ((val) ? (bit) : 0))
109 #define test_bit(num, bit) (((num) & (bit)) != 0)
112 const char*
strip_prefix(
const char* str,
const char* prefix);
116 void*
memdup(
const void* src,
size_t size);
138 #define FNV32_INITIAL_STATE ((uint32_t)2166136261)
140 #define FNV32_PRIME ((uint32_t)16777619)
151 inline uint32_t
fnv32_hash(uint32_t state,
const void* buf,
size_t len) {
152 const uint8_t* ptr = (
const uint8_t*)buf;
153 const uint8_t* end = ptr + len;
154 for (; ptr != end; ptr++) state = (state ^ *ptr) *
FNV32_PRIME;
A pair of 2D coordinates, used for addressing the Game::board_grid.
bool coords_same(Coords a, Coords b)
Checks if two Coords pairs are equal.
A wrapper around random number generators.
int(* random_range)(struct Rng *self, int min, int max)
Generates and returns a value in the range [min; max) (i.e. from min inclusive to max exclusive).
Rng init_stdlib_rng(void)
Returns an RNG implementation based on the rand function from <stdlib.h> (and seeds it with srand).
void * memdup(const void *src, size_t size)
A shorthand for malloc + memcpy (analogous to strdup).
const Coords NEIGHBOR_TO_COORDS[NEIGHBOR_MAX]
A table that maps Neighbor variants to relative Coords.
const Coords DIRECTION_TO_COORDS[DIRECTION_MAX]
A table that maps Direction variants to relative Coords.
bool parse_number(const char *str, long *result)
Converts a string into a number, returns false if the string was invalid.
const Neighbor DIRECTION_TO_NEIGHBOR[DIRECTION_MAX]
A table that maps Direction variants to corresponding Neighbor variants.
#define FNV32_PRIME
A constant for fnv32_hash.
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.
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,...