12 #define WIN32_LEAN_AND_MEAN 
   48   size_t prefix_len = strlen(prefix);
 
   49   return strncmp(prefix, str, prefix_len) == 0 ? str + prefix_len : NULL;
 
   66   while (isspace(*str)) str++; 
 
   68   *result = strtol(str, &end, 10);
 
   69   while (isspace(*end)) end++; 
 
   79 void* 
memdup(
const void* src, 
size_t size) {
 
   81   void* dest = malloc(size);
 
   82   if (dest != NULL) memcpy(dest, src, size);
 
   91   GetSystemTimeAsFileTime(&t);
 
   92   i.u.LowPart = t.dwLowDateTime;
 
   93   i.u.HighPart = t.dwHighDateTime;
 
   94   ULONGLONG seed = i.QuadPart / 1000;
 
   96   struct timespec ts, res;
 
   97   clock_getres(CLOCK_REALTIME, &res);
 
   98   clock_gettime(CLOCK_REALTIME, &ts);
 
   99   unsigned long seed = ts.tv_nsec / res.tv_nsec;
 
  101   srand((
unsigned int)seed);
 
  108   unsigned int n = (max - min <= RAND_MAX) ? (max - min + 1U) : (RAND_MAX + 1U);
 
  109   unsigned int x = (RAND_MAX + 1U) / n;
 
  110   unsigned int y = x * n;
 
  130 extern uint32_t 
fnv32_hash(uint32_t state, 
const void* buf, 
size_t len);
 
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.
 
static void random_init(void)
 
const Neighbor DIRECTION_TO_NEIGHBOR[DIRECTION_MAX]
A table that maps Direction variants to corresponding Neighbor variants.
 
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.
 
static int random_range(Rng *rng, int min, int max)
 
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,...
 
#define UNUSED(var)
Helper for silencing warnings about unused variables.