38 int checked_players = 0;
39 while (checked_players < game->players_count) {
103 entry_data->
target = target;
Functions for working with the game board (and the specifics of its encoding)
#define is_fish_tile(tile)
#define is_penguin_tile(tile)
#define PENGUIN_TILE(player_id)
#define is_water_tile(tile)
#define get_tile_player_id(tile)
#define get_tile_fish(tile)
The core of the unified game logic library, contains the Game struct.
@ GAME_PHASE_PLACEMENT
Set by placement_begin.
@ GAME_PHASE_SETUP_DONE
Set by game_end_setup, placement_end, movement_end.
@ GAME_LOG_ENTRY_PLACEMENT
See GameLogPlacement.
Placement phase functions.
@ PLACEMENT_ALL_PENGUINS_PLACED
@ PLACEMENT_NO_MORE_FREE_TILES
@ PLACEMENT_MULTIPLE_FISH
@ PLACEMENT_ENEMY_PENGUIN
@ PLACEMENT_OUT_OF_BOUNDS
A pair of 2D coordinates, used for addressing the Game::board_grid.
An entry in the Game::log_buffer, implemented as a tagged union.
union GameLogEntry::GameLogEntryData data
A GameLogEntry created by place_penguin.
The central struct of the application, holds the game data and settings.
ALWAYS_INLINE bool is_tile_in_bounds(const Game *game, Coords coords)
Checks if the given coords are within the bounds of the board.
void undo_place_penguin(Game *game)
Removes a GameLogPlacement entry from the log and undoes it.
Player * game_get_current_player(const Game *self)
A shorthand for calling game_get_player with Game::current_player_index.
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...
bool validate_placement_simple(const Game *game, Coords target)
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.
void game_add_player_penguin(Game *self, int idx, Coords coords)
void game_set_current_player(Game *self, int idx)
Sets Game::current_player_index and creates a GameLogPlayerChange log entry.
int penguins_per_player
Use game_set_penguins_per_player for setting this.
GamePhase phase
The current state of the state machine, initially set to GAME_PHASE_NONE. Use game_set_phase for sett...
void game_set_phase(Game *self, GamePhase phase)
Sets the current Game::phase and creates a GameLogPhaseChange log entry.
void game_remove_player_penguin(Game *self, int idx, Coords coords)
const GameLogEntry * game_pop_log_entry(Game *self, GameLogEntryType expected_type)
Pops the last entry off the top of the stack if its type matches the expected_type (this is used as a...
int board_width
Use setup_board for setting this.
bool any_valid_placement_exists(const Game *game)
void placement_begin(Game *game)
Enters the GAME_PHASE_PLACEMENT phase, can only be called in GAME_PHASE_SETUP_DONE.
int board_height
Use setup_board for setting this.
PlacementError validate_placement(const Game *game, Coords target)
int placement_switch_player(Game *game)
Performs the player switching logic for the placement phase.
int current_player_index
A negative value means that there is no current player selected. Use game_set_current_player for sett...
int players_count
Use game_set_players_count for setting this.
void place_penguin(Game *game, Coords target)
Creates a GameLogPlacement entry. The requested placement must be valid.
Player * game_get_player(const Game *self, int idx)
Returns a pointer to the player at the given index. Fails if the index isn't within the bounds of the...
void placement_end(Game *game)
Exits the GAME_PHASE_PLACEMENT phase and switches to GAME_PHASE_SETUP_DONE.
GameLogEntry * game_push_log_entry(Game *self, GameLogEntryType type)
Creates a GameLogEntry, sets its GameLogEntry::type, pushes it on top of the stack (reallocating the ...
Holds the data of the players of the Game.
short id
The unique ID, usually (but not necessarily) is just index + 1.
int moves_count
The number of moves (penguin placements and movements) made by the player.
int points
The score of the player, i.e. the number of collected fish.
int penguins_count
The length of the penguins array.
GameLogPlacement placement