penguins
1.0.0
|
Go to the source code of this file.
Macros | |
#define | fnv32_hash_value(value) state = fnv32_hash(state, &value, sizeof(value)) |
#define | fnv32_hash_array(ptr, len) state = fnv32_hash(state, ptr, sizeof(*ptr) * len) |
Functions | |
Game * | game_new (void) |
Constructs a Game. Allocates memory for storing the struct itself, setting all fields to default values, and returns a pointer to it. More... | |
Game * | game_clone (const Game *other) |
Creates a (deep) copy of another Game. More... | |
void | game_free (Game *self) |
Destroys a Game, freeing the memory allocated for the struct itself and all associated internal lists. More... | |
uint32_t | game_compute_state_hash (const Game *self) |
Computes a hash of the game state part of the Game, i.e. the fields that change while playing the game, excluding settings, log, etc. Was used for debugging, currently unused. More... | |
void | game_set_log_capacity (Game *self, size_t capacity) |
Sets Game::log_capacity and allocates that many elements in Game::log_buffer. If the new capacity is less than Game::log_length the Game::log_buffer will be truncated. More... | |
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 Game::log_buffer if necessary) and returns a pointer to it. More... | |
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 precaution) and returns a pointer to it. More... | |
const GameLogEntry * | game_get_log_entry (const Game *self, size_t idx) |
Returns a pointer to the entry at the given index. Note that the returned pointer is const because the log entries are read-only once they have been pushed. More... | |
void | game_set_phase (Game *self, GamePhase phase) |
Sets the current Game::phase and creates a GameLogPhaseChange log entry. More... | |
void | game_set_current_player (Game *self, int idx) |
Sets Game::current_player_index and creates a GameLogPlayerChange log entry. More... | |
void | game_begin_setup (Game *self) |
Switches to the GAME_PHASE_SETUP phase, can only be called in GAME_PHASE_NONE. Should be called right away after constructing a Game. More... | |
void | game_end_setup (Game *self) |
Verifies that all fields have been initialized and configured and switches the phase from GAME_PHASE_SETUP to GAME_PHASE_SETUP_DONE. More... | |
void | game_set_penguins_per_player (Game *self, int value) |
Sets Game::penguins_per_player (the value mustn't be negative) and allocates Player::penguins lists of all players. Available only in the GAME_PHASE_SETUP phase. More... | |
void | game_set_players_count (Game *self, int count) |
Sets Game::players_count (the value mustn't be negative) and allocates the Game::players list. Available only in the GAME_PHASE_SETUP phase. More... | |
void | game_set_player_name (Game *self, int idx, const char *name) |
Sets the Player::name of a player at the given index. Only available in the GAME_PHASE_SETUP phase. More... | |
void | game_add_player_penguin (Game *self, int idx, Coords coords) |
void | game_remove_player_penguin (Game *self, int idx, Coords coords) |
void | game_advance_state (Game *self) |
The all-in-one phase switcher that progresses of the game. More... | |
void | game_end (Game *self) |
Switches to the GAME_PHASE_END phase. More... | |
void | game_rewind_state_to_log_entry (Game *self, size_t target_entry) |
Successively undoes or redoes log entries in order to reset the game state to the entry at the given index. Sets Game::log_current to the selected entry afterwards. More... | |
bool | game_check_player_index (const Game *self, int idx) |
Checks if idx is within the bounds of Game::players. More... | |
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 Game::players list. More... | |
Player * | game_get_current_player (const Game *self) |
A shorthand for calling game_get_player with Game::current_player_index. More... | |
int | game_find_player_by_id (const Game *self, short id) |
Returns an index of the player or -1 if no such player was found. More... | |
Coords * | game_find_player_penguin (const Game *self, int idx, Coords coords) |
Finds a penguin with the given coordinates in the Player::penguins list of a player at idx and returns a pointer to it. Returns NULL if no such penguin is found. More... | |
#define fnv32_hash_value | ( | value | ) | state = fnv32_hash(state, &value, sizeof(value)) |
#define fnv32_hash_array | ( | ptr, | |
len | |||
) | state = fnv32_hash(state, ptr, sizeof(*ptr) * len) |
Game * game_new | ( | void | ) |
Constructs a Game. Allocates memory for storing the struct itself, setting all fields to default values, and returns a pointer to it.
Definition at line 15 of file game.c.
Referenced by GamePanel::GamePanel().
Creates a (deep) copy of another Game.
Definition at line 36 of file game.c.
Referenced by BotThread::BotThread().
void game_free | ( | Game * | self | ) |
uint32_t game_compute_state_hash | ( | const Game * | self | ) |
void game_set_log_capacity | ( | Game * | self, |
size_t | capacity | ||
) |
Sets Game::log_capacity and allocates that many elements in Game::log_buffer. If the new capacity is less than Game::log_length the Game::log_buffer will be truncated.
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 Game::log_buffer if necessary) and returns a pointer to it.
NULL
if Game::log_disabled is set to true
!If some entries were undone and the user then pushes a new entry, discards all the undone entries.
const GameLogEntry * game_pop_log_entry | ( | Game * | self, |
GameLogEntryType | expected_type | ||
) |
const GameLogEntry * game_get_log_entry | ( | const Game * | self, |
size_t | idx | ||
) |
Returns a pointer to the entry at the given index. Note that the returned pointer is const because the log entries are read-only once they have been pushed.
Definition at line 173 of file game.c.
Referenced by GamePanel::describe_game_log_entry(), LogEntryViewerController::on_activated(), and LogEntryViewerController::paint_overlay().
Sets the current Game::phase and creates a GameLogPhaseChange log entry.
void game_set_current_player | ( | Game * | self, |
int | idx | ||
) |
Sets Game::current_player_index and creates a GameLogPlayerChange log entry.
void game_begin_setup | ( | Game * | self | ) |
Switches to the GAME_PHASE_SETUP phase, can only be called in GAME_PHASE_NONE. Should be called right away after constructing a Game.
Definition at line 209 of file game.c.
Referenced by GamePanel::GamePanel().
void game_end_setup | ( | Game * | self | ) |
Verifies that all fields have been initialized and configured and switches the phase from GAME_PHASE_SETUP to GAME_PHASE_SETUP_DONE.
The Game is considered completely initialized when:
Definition at line 224 of file game.c.
Referenced by GamePanel::GamePanel().
void game_set_penguins_per_player | ( | Game * | self, |
int | value | ||
) |
Sets Game::penguins_per_player (the value mustn't be negative) and allocates Player::penguins lists of all players. Available only in the GAME_PHASE_SETUP phase.
Definition at line 248 of file game.c.
Referenced by GamePanel::GamePanel().
void game_set_players_count | ( | Game * | self, |
int | count | ||
) |
Sets Game::players_count (the value mustn't be negative) and allocates the Game::players list. Available only in the GAME_PHASE_SETUP phase.
Definition at line 264 of file game.c.
Referenced by GamePanel::GamePanel().
void game_set_player_name | ( | Game * | self, |
int | idx, | ||
const char * | name | ||
) |
Sets the Player::name of a player at the given index. Only available in the GAME_PHASE_SETUP phase.
A copy of the name string will be created. A NULL
pointer can be passed.
Definition at line 287 of file game.c.
Referenced by GamePanel::GamePanel().
Fails when Player::penguins_count is already at the maximum value (Game::penguins_per_player).
void game_advance_state | ( | Game * | self | ) |
The all-in-one phase switcher that progresses of the game.
Essentially handles the basic progression logic (and the edge cases): first switches the game to the placement phase, if in placement phase switches between players, then (once all penguins have been placed) moves on to the movement phase, afterwards again switches between player turns, and finally ends the game when no player can make a move.
Was added to simplify the logic of phase switching in the GUI.
Definition at line 329 of file game.c.
Referenced by GamePanel::update_game_state().
void game_end | ( | Game * | self | ) |
Switches to the GAME_PHASE_END phase.
void game_rewind_state_to_log_entry | ( | Game * | self, |
size_t | target_entry | ||
) |
Successively undoes or redoes log entries in order to reset the game state to the entry at the given index. Sets Game::log_current to the selected entry afterwards.
Definition at line 368 of file game.c.
Referenced by LogEntryViewerController::on_activated(), and GamePanel::on_show_current_turn_clicked().
|
inline |
Checks if idx
is within the bounds of Game::players.
Definition at line 387 of file game.h.
Referenced by GamePanel::get_controller_for_current_turn(), and CanvasPanel::get_selected_penguin_coords().
Returns a pointer to the player at the given index. Fails if the index isn't within the bounds of the Game::players list.
Definition at line 394 of file game.h.
Referenced by GameEndDialog::GameEndDialog(), CanvasPanel::get_selected_penguin_coords(), and PlayerInfoBox::update_data().
A shorthand for calling game_get_player with Game::current_player_index.
Definition at line 401 of file game.h.
Referenced by PlayerMovementController::update_tile_attributes().
|
inline |
Returns an index of the player or -1
if no such player was found.
Definition at line 407 of file game.h.
Referenced by CanvasPanel::paint_board().