14   assert(width > 0 && height > 0);
 
   39   for (
int y = 0; y < h; y++) {
 
   40     for (
int x = 0; x < w; x++) {
 
   45   for (
int i = 0; i < w + h; i++) {
 
   46     Coords coords = { w / 2, h / 2 };
 
   47     for (
int j = 0; j < w + h; j++) {
 
   49         case 0: coords.
x += 1; 
break;
 
   50         case 1: coords.
y += 1; 
break;
 
   51         case 2: coords.
x -= 1; 
break;
 
   52         case 3: coords.
y -= 1; 
break;
 
void generate_board_random(Game *game, Rng *rng)
Generates the board by setting every tile purely randomly. The resulting board will look sort of like...
 
void generate_board_island(Game *game, Rng *rng)
Generates the board which looks sort of like a big icy island.
 
Functions for working with the game board (and the specifics of its encoding)
 
@ TILE_DIRTY
Set when a tile is changed with set_tile, can be unset by the UI. All tiles initially have this attri...
 
The core of the unified game logic library, contains the Game struct.
 
@ GAME_PHASE_SETUP
Set by game_begin_setup.
 
A pair of 2D coordinates, used for addressing the Game::board_grid.
 
The central struct of the application, holds the game data and settings.
 
ALWAYS_INLINE void set_all_tiles_attr(Game *game, short attr, bool value)
Sets the attribute attr on all tiles.
 
ALWAYS_INLINE bool is_tile_in_bounds(const Game *game, Coords coords)
Checks if the given coords are within the bounds of the board.
 
ALWAYS_INLINE void set_tile(Game *game, Coords coords, short value)
Sets the value of the tile at coords (and also sets the attribute TILE_DIRTY). Fails if coords are ou...
 
ALWAYS_INLINE short get_tile(const Game *game, Coords coords)
Returns the value of the tile at coords. Fails if coords are outside the bounds.
 
GamePhase phase
The current state of the state machine, initially set to GAME_PHASE_NONE. Use game_set_phase for sett...
 
int board_width
Use setup_board for setting this.
 
void setup_board(Game *game, int width, int height)
Sets Game::board_width and Game::board_height and allocates Game::board_grid and Game::tile_attribute...
 
short * tile_attributes
Stores auxilary data of grid tiles for use in the UIs. Use setup_board for initializing,...
 
short * board_grid
A 2D grid represented as a 1D array which stores the tiles of the board. Use setup_board for initiali...
 
ALWAYS_INLINE bool get_tile_attr(const Game *game, Coords coords, short attr)
Checks whether the attribute attr of the tile at coords is set.
 
int board_height
Use setup_board for setting this.
 
ALWAYS_INLINE void set_tile_attr(Game *game, Coords coords, short attr, bool value)
Sets (or resets) the attribute attr of the tile at coords.
 
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).
 
#define free_and_clear(ptr)
Calls free on a pointer and then sets it to NULL.