penguins  1.0.0
Game Struct Reference

Detailed Description

The central struct of the application, holds the game data and settings.

This struct contains the common information used everywhere in the game, so you'll see it being passed around in almost all functions. It is modelled as a state machine: there is a field that holds the current "state", called phase (note that there are way more phases than just the placement and movement phases described by the rules of the game) and to do something useful with it you have to switch it between those phases. The functions for transitioning between phases typically have requirements for what has to be done prior to making the transition (e.g. game_end_setup verifies that everything has been initialized properly) and from what other phase the transition can occur (e.g. you can't call game_begin_setup once the game has already been configured). The functions relating to various phases also typically check that the game is in the correct state (e.g. obviously, place_penguin only works in the placement phase), although if the function doesn't modify any internal state then there is no harm in not performing the check (e.g. it is possible to call validate_movement even in the placement phase).

It also records the history of performed actions (player moves, certain state changes, apart from the changes of the settings during setup) in a log, making it possible to undo or redo any of them with game_rewind_state_to_log_entry.

See also
https://en.wikipedia.org/wiki/Finite-state_machine

This struct is implemented sort of as a class in my poor-man's OOP system. Basically, you shouldn't initialize the struct yourself, instead you have to call the constructor game_new, and once you are done with using it, you must to invoke the destructor game_free. The "methods" of the class are just functions which take Game* or const Game* (when the method doesn't actually change any fields) as the first argument.

I don't adhere to the traditional OOP style dogmatically though: all fields of the struct are exposed instead of it being fully opaque and having a getter and a setter for every field, and some of the "methods" technically reside in other files (notably board.c, placement.c, movement.c). Although getters and setters are used where it makes sense: setting some fields is not as trivial as just writing a single value, and getters can ensure the correctness of, for example, access into arrays (i.e. check that the index is in the bounds of the array), e.g. game_get_player. In short, if a getter or a setter for a given field or array exists – you should use it, otherwise accessing the field directly is perfectly fine.

So in general, the most basic usage of this struct is:

Game* game = game_new();
// ...
// ...
// ...
game_free(game);
The central struct of the application, holds the game data and settings.
Definition: game.h:237
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...
Definition: game.c:209
void game_end_setup(Game *self)
Verifies that all fields have been initialized and configured and switches the phase from GAME_PHASE_...
Definition: game.c:224
void placement_begin(Game *game)
Enters the GAME_PHASE_PLACEMENT phase, can only be called in GAME_PHASE_SETUP_DONE.
Definition: placement.c:11
void movement_begin(Game *game)
Enters the GAME_PHASE_MOVEMENT phase, can only be called in GAME_PHASE_SETUP_DONE.
Definition: movement.c:11
void movement_end(Game *game)
Exits the GAME_PHASE_MOVEMENT phase and switches to GAME_PHASE_SETUP_DONE.
Definition: movement.c:20
void placement_end(Game *game)
Exits the GAME_PHASE_PLACEMENT phase and switches to GAME_PHASE_SETUP_DONE.
Definition: placement.c:20
Game * game_new(void)
Constructs a Game. Allocates memory for storing the struct itself, setting all fields to default valu...
Definition: game.c:15
void game_free(Game *self)
Destroys a Game, freeing the memory allocated for the struct itself and all associated internal lists...
Definition: game.c:68

When working in C++, it is possible to have this struct automatically managed with the help of a unique_ptr :

std::unique_ptr<Game, decltype(&game_free)> game(game_new(), &game_free);

Definition at line 237 of file game.h.

Data Fields

GamePhase phase
 The current state of the state machine, initially set to GAME_PHASE_NONE. Use game_set_phase for setting this. More...
 
Players
Playerplayers
 The list of players with length players_count. Initialized with game_set_players_count. Use game_get_player for accessing this. More...
 
int players_count
 Use game_set_players_count for setting this. More...
 
int penguins_per_player
 Use game_set_penguins_per_player for setting this. More...
 
int current_player_index
 A negative value means that there is no current player selected. Use game_set_current_player for setting this. More...
 
Board
int board_width
 Use setup_board for setting this. More...
 
int board_height
 Use setup_board for setting this. More...
 
short * board_grid
 A 2D grid represented as a 1D array which stores the tiles of the board. Use setup_board for initializing, get_tile and set_tile for accessing. More...
 
short * tile_attributes
 Stores auxilary data of grid tiles for use in the UIs. Use setup_board for initializing, get_tile_attr and set_tile_attr for accessing. More...
 
Logging
bool log_disabled
 Signals whether new log entries can be created. See game_push_log_entry. More...
 
GameLogEntrylog_buffer
 The stack of log entries. Use game_push_log_entry, game_pop_log_entry and game_get_log_entry for modifying and accessing. More...
 
size_t log_capacity
 The total number of elements log_buffer was allocated for (i.e. pushing more requires reallocating it). More...
 
size_t log_length
 The actual number of entries in log_buffer. game_push_log_entry and game_pop_log_entry affects this. More...
 
size_t log_current
 The index of the currently selected log entry. Normally equals log_length, if less than log_length an older entry is being viewed. More...
 

Related Functions

(Note that these are not member functions.)

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_attributes. Can only be called within GAME_PHASE_SETUP. The width and height values must be positive. More...
 
Gamegame_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...
 
Gamegame_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...
 
GameLogEntrygame_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 GameLogEntrygame_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 GameLogEntrygame_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...
 
Playergame_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...
 
Playergame_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...
 
Coordsgame_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...
 
void movement_begin (Game *game)
 Enters the GAME_PHASE_MOVEMENT phase, can only be called in GAME_PHASE_SETUP_DONE. More...
 
void movement_end (Game *game)
 Exits the GAME_PHASE_MOVEMENT phase and switches to GAME_PHASE_SETUP_DONE. More...
 
int movement_switch_player (Game *game)
 Performs the player switching logic for the movement phase. More...
 
bool any_valid_player_move_exists (const Game *game, int player_idx)
 
MovementError validate_movement_start (const Game *game, Coords start)
 
MovementError validate_movement (const Game *game, Coords start, Coords target, Coords *fail)
 
void move_penguin (Game *game, Coords start, Coords target)
 Creates a GameLogMovement entry. The requested move must be valid. More...
 
void undo_move_penguin (Game *game)
 Removes a GameLogMovement entry from the log and undoes it. More...
 
int count_obstructed_directions (const Game *game, Coords penguin)
 
PossibleSteps calculate_penguin_possible_moves (const Game *game, Coords start)
 
void placement_begin (Game *game)
 Enters the GAME_PHASE_PLACEMENT phase, can only be called in GAME_PHASE_SETUP_DONE. More...
 
void placement_end (Game *game)
 Exits the GAME_PHASE_PLACEMENT phase and switches to GAME_PHASE_SETUP_DONE. More...
 
int placement_switch_player (Game *game)
 Performs the player switching logic for the placement phase. More...
 
bool any_valid_placement_exists (const Game *game)
 
bool validate_placement_simple (const Game *game, Coords target)
 
PlacementError validate_placement (const Game *game, Coords target)
 
void place_penguin (Game *game, Coords target)
 Creates a GameLogPlacement entry. The requested placement must be valid. More...
 
void undo_place_penguin (Game *game)
 Removes a GameLogPlacement entry from the log and undoes it. More...
 
Functions for accessing the board tiles and attributes

All of these are inline because they are used very very frequently in virtually every module of the app, thus in computation-heavy code, such as the bot, inlining those functions enables very efficient optimizations by the compiler (the bot in particular has been sped up 2 times).

ALWAYS_INLINE bool is_tile_in_bounds (const Game *game, Coords coords)
 Checks if the given coords are within the bounds of the board. More...
 
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. More...
 
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. More...
 
ALWAYS_INLINE void set_all_tiles_attr (Game *game, short attr, bool value)
 Sets the attribute attr on all tiles. More...
 
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. More...
 
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 outside the bounds. More...
 

Field Documentation

◆ phase

GamePhase Game::phase

◆ players

Player* Game::players

The list of players with length players_count. Initialized with game_set_players_count. Use game_get_player for accessing this.

Definition at line 249 of file game.h.

Referenced by game_clone().

◆ players_count

◆ penguins_per_player

int Game::penguins_per_player

Use game_set_penguins_per_player for setting this.

Definition at line 253 of file game.h.

Referenced by placement_switch_player().

◆ current_player_index

◆ board_width

◆ board_height

◆ board_grid

short* Game::board_grid

A 2D grid represented as a 1D array which stores the tiles of the board. Use setup_board for initializing, get_tile and set_tile for accessing.

The 1D representation works as follows. Say we have a grid like this:

[ a, b, c, d ]
[ e, f, g, h ]
[ i, j, k, l ]
[ m, n, o, p ]

It will be laid out in memory like this:

[ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p ]
|--------| |--------| |--------| |--------|
row 1 row 2 row 3 row 4

As you can see, the second row goes immediately after the first one in the array, the third one after the second one, and so on and so on. So, to determine the actual location of a tile in this sequential representation, we can use the formula index = y * width + x. The length of the whole array, consequently, is width * height. This method is used primarily for simplicity – it is easier to manage memory of a single array than to allocate an array of arrays.

See also
https://en.wikipedia.org/wiki/Row-_and_column-major_order

The tiles themselves are encoded as integers in the following way:

  1. n = 0 - a water tile.
  2. n = 1, 2, 3, ... - an ice tile with n fish.
  3. n = -1, -2, -3, ... - an ice tile with a penguin of a player with ID n.

Since we only have a few small values that we want to store, to conserve memory the type short (2 bytes long) is used instead of an int (4 bytes long).

Definition at line 306 of file game.h.

Referenced by BotState::bot_flood_fill_check(), BotState::bot_flood_fill_mark(), game_clone(), get_tile(), set_tile(), and setup_board().

◆ tile_attributes

short* Game::tile_attributes

Stores auxilary data of grid tiles for use in the UIs. Use setup_board for initializing, get_tile_attr and set_tile_attr for accessing.

These auxiliary attributes are simply a bitfield – a number where every bit is a flag which is either on or off, sort of like a struct with bool fields, but compactly represented in memory. This representation was chosen because of how simple it was to implement while being sufficient for the needs of the UI. The utils.h file contains some macros for working with such bitfields, though in the case of tile attributes, convenient functions are provided for this: set_tile_attr, get_tile_attr and set_all_tiles_attr. The list of used attributes can be seen in the TileAttribute and GuiTileAttribute enums. Internally, tile attributes are stored in the same grid layout as the tiles themselves are in board_grid.

See also
https://en.wikipedia.org/wiki/Bit_field

The attributes system was initially written for the graphical interface and resided in CanvasPanel, but I have moved it since into the common library code because for the potential needs of other UIs (but really because it was more convenient that way).

Definition at line 330 of file game.h.

Referenced by game_clone(), get_tile_attr(), set_tile_attr(), and setup_board().

◆ log_disabled

bool Game::log_disabled

Signals whether new log entries can be created. See game_push_log_entry.

Definition at line 339 of file game.h.

◆ log_buffer

GameLogEntry* Game::log_buffer

The stack of log entries. Use game_push_log_entry, game_pop_log_entry and game_get_log_entry for modifying and accessing.

See also
https://en.wikipedia.org/wiki/Stack_(abstract_data_type)

Definition at line 343 of file game.h.

Referenced by game_clone().

◆ log_capacity

size_t Game::log_capacity

The total number of elements log_buffer was allocated for (i.e. pushing more requires reallocating it).

game_set_log_capacity can be called during setup to pre-allocate the buffer.

Definition at line 348 of file game.h.

Referenced by game_clone().

◆ log_length

size_t Game::log_length

The actual number of entries in log_buffer. game_push_log_entry and game_pop_log_entry affects this.

Definition at line 351 of file game.h.

Referenced by LogEntryViewerController::on_activated().

◆ log_current

size_t Game::log_current

The index of the currently selected log entry. Normally equals log_length, if less than log_length an older entry is being viewed.

Definition at line 354 of file game.h.

Friends And Related Function Documentation

◆ setup_board()

void setup_board ( Game game,
int  width,
int  height 
)
related

Sets Game::board_width and Game::board_height and allocates Game::board_grid and Game::tile_attributes. Can only be called within GAME_PHASE_SETUP. The width and height values must be positive.

Definition at line 12 of file board.c.

Referenced by load_game_state(), run_autonomous_mode(), run_interactive_mode(), setup_test_game(), and test_game_clone().

◆ is_tile_in_bounds()

◆ get_tile_attr()

ALWAYS_INLINE bool get_tile_attr ( const Game game,
Coords  coords,
short  attr 
)
related

Checks whether the attribute attr of the tile at coords is set.

See also
Game::tile_attributes

Definition at line 78 of file board.h.

◆ set_tile_attr()

ALWAYS_INLINE void set_tile_attr ( Game game,
Coords  coords,
short  attr,
bool  value 
)
related

Sets (or resets) the attribute attr of the tile at coords.

See also
Game::tile_attributes

Definition at line 86 of file board.h.

Referenced by set_all_tiles_attr(), and set_tile().

◆ set_all_tiles_attr()

ALWAYS_INLINE void set_all_tiles_attr ( Game game,
short  attr,
bool  value 
)
related

Sets the attribute attr on all tiles.

See also
Game::tile_attributes

Definition at line 95 of file board.h.

Referenced by setup_board().

◆ get_tile()

◆ set_tile()

ALWAYS_INLINE void set_tile ( Game game,
Coords  coords,
short  value 
)
related

Sets the value of the tile at coords (and also sets the attribute TILE_DIRTY). Fails if coords are outside the bounds.

See also
Game::board_grid

Definition at line 117 of file board.h.

Referenced by generate_board_island(), generate_board_random(), load_game_state(), move_penguin(), place_penguin(), setup_test_game(), undo_move_penguin(), and undo_place_penguin().

◆ game_new()

◆ game_clone()

Game * game_clone ( const Game other)
related

Creates a (deep) copy of another Game.

Definition at line 36 of file game.c.

Referenced by test_game_clone().

◆ game_free()

◆ game_compute_state_hash()

uint32_t game_compute_state_hash ( const Game self)
related

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.

Definition at line 87 of file game.c.

◆ game_set_log_capacity()

void game_set_log_capacity ( Game self,
size_t  capacity 
)
related

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.

Definition at line 121 of file game.c.

Referenced by game_push_log_entry().

◆ game_push_log_entry()

GameLogEntry * game_push_log_entry ( Game self,
GameLogEntryType  type 
)
related

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.

Note
Returns 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.

Definition at line 137 of file game.c.

Referenced by game_set_current_player(), game_set_phase(), move_penguin(), and place_penguin().

◆ game_pop_log_entry()

const GameLogEntry * game_pop_log_entry ( Game self,
GameLogEntryType  expected_type 
)
related

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.

Definition at line 156 of file game.c.

Referenced by game_rewind_state_to_log_entry(), undo_move_penguin(), and undo_place_penguin().

◆ game_get_log_entry()

const GameLogEntry * game_get_log_entry ( const Game self,
size_t  idx 
)
related

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 game_rewind_state_to_log_entry().

◆ game_set_phase()

void game_set_phase ( Game self,
GamePhase  phase 
)
related

Sets the current Game::phase and creates a GameLogPhaseChange log entry.

Definition at line 181 of file game.c.

Referenced by game_begin_setup(), game_end(), game_end_setup(), movement_begin(), movement_end(), placement_begin(), and placement_end().

◆ game_set_current_player()

◆ game_begin_setup()

void game_begin_setup ( Game self)
related

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 run_autonomous_mode(), run_interactive_mode(), setup_test_game(), and test_game_clone().

◆ game_end_setup()

void game_end_setup ( Game self)
related

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:

  1. The board has been created with setup_board
  2. The players list has been created with game_set_players_count
  3. The penguins lists have been created with game_set_penguins_per_player
  4. The names of all players have been assigned with game_set_player_name

Definition at line 224 of file game.c.

Referenced by game_advance_state(), run_autonomous_mode(), run_interactive_mode(), and setup_test_game().

◆ game_set_penguins_per_player()

void game_set_penguins_per_player ( Game self,
int  value 
)
related

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 load_game_state(), run_autonomous_mode(), run_interactive_mode(), setup_test_game(), and test_game_clone().

◆ game_set_players_count()

void game_set_players_count ( Game self,
int  count 
)
related

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 load_game_state(), run_autonomous_mode(), run_interactive_mode(), setup_test_game(), and test_game_clone().

◆ game_set_player_name()

void game_set_player_name ( Game self,
int  idx,
const char *  name 
)
related

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 load_game_state(), run_interactive_mode(), setup_test_game(), and test_game_clone().

◆ game_add_player_penguin()

void game_add_player_penguin ( Game self,
int  idx,
Coords  coords 
)
related

Fails when Player::penguins_count is already at the maximum value (Game::penguins_per_player).

Definition at line 297 of file game.c.

Referenced by load_game_state(), place_penguin(), and setup_test_game().

◆ game_remove_player_penguin()

void game_remove_player_penguin ( Game self,
int  idx,
Coords  coords 
)
related

Fails if the player doesn't have a penguin at the given coordinates.

Definition at line 306 of file game.c.

Referenced by undo_place_penguin().

◆ game_advance_state()

void game_advance_state ( Game self)
related

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.

◆ game_end()

void game_end ( Game self)
related

Switches to the GAME_PHASE_END phase.

Definition at line 358 of file game.c.

Referenced by game_advance_state(), and run_interactive_mode().

◆ game_rewind_state_to_log_entry()

void game_rewind_state_to_log_entry ( Game self,
size_t  target_entry 
)
related

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.

◆ game_check_player_index()

bool game_check_player_index ( const Game self,
int  idx 
)
related

Checks if idx is within the bounds of Game::players.

Definition at line 387 of file game.h.

Referenced by game_get_player().

◆ game_get_player()

◆ game_get_current_player()

◆ game_find_player_by_id()

int game_find_player_by_id ( const Game self,
short  id 
)
related

Returns an index of the player or -1 if no such player was found.

Definition at line 407 of file game.h.

Referenced by print_board().

◆ game_find_player_penguin()

Coords * game_find_player_penguin ( const Game self,
int  idx,
Coords  coords 
)
related

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.

Definition at line 420 of file game.h.

Referenced by game_remove_player_penguin(), move_penguin(), and undo_move_penguin().

◆ movement_begin()

void movement_begin ( Game game)
related

◆ movement_end()

void movement_end ( Game game)
related

Exits the GAME_PHASE_MOVEMENT phase and switches to GAME_PHASE_SETUP_DONE.

Definition at line 20 of file movement.c.

Referenced by game_advance_state(), interactive_movement(), and run_autonomous_mode().

◆ movement_switch_player()

int movement_switch_player ( Game game)
related

Performs the player switching logic for the movement phase.

Finds the next player who can make a move, sets Game::current_player_index to that player and returns their index. If no players can make any moves returns a negative number.

Definition at line 31 of file movement.c.

Referenced by game_advance_state(), interactive_movement(), and run_autonomous_mode().

◆ any_valid_player_move_exists()

bool any_valid_player_move_exists ( const Game game,
int  player_idx 
)
related

◆ validate_movement_start()

MovementError validate_movement_start ( const Game game,
Coords  start 
)
related

Definition at line 58 of file movement.c.

Referenced by handle_movement_input(), and validate_movement().

◆ validate_movement()

MovementError validate_movement ( const Game game,
Coords  start,
Coords  target,
Coords fail 
)
related

◆ move_penguin()

void move_penguin ( Game game,
Coords  start,
Coords  target 
)
related

◆ undo_move_penguin()

void undo_move_penguin ( Game game)
related

Removes a GameLogMovement entry from the log and undoes it.

Definition at line 142 of file movement.c.

Referenced by BotState::bot_rate_move(), and game_rewind_state_to_log_entry().

◆ count_obstructed_directions()

int count_obstructed_directions ( const Game game,
Coords  penguin 
)
related

◆ calculate_penguin_possible_moves()

PossibleSteps calculate_penguin_possible_moves ( const Game game,
Coords  start 
)
related

Definition at line 64 of file movement.h.

Referenced by BotState::bot_generate_all_moves_list().

◆ placement_begin()

void placement_begin ( Game game)
related

Enters the GAME_PHASE_PLACEMENT phase, can only be called in GAME_PHASE_SETUP_DONE.

Definition at line 11 of file placement.c.

Referenced by game_advance_state(), interactive_placement(), and run_autonomous_mode().

◆ placement_end()

void placement_end ( Game game)
related

Exits the GAME_PHASE_PLACEMENT phase and switches to GAME_PHASE_SETUP_DONE.

Definition at line 20 of file placement.c.

Referenced by game_advance_state(), interactive_placement(), and run_autonomous_mode().

◆ placement_switch_player()

int placement_switch_player ( Game game)
related

Performs the player switching logic for the placement phase.

Finds the next player who can make a placement, switches Game::current_player_index to that player and returns their index. If there are no more valid placements, returns a PlacementError value, which are all negative numbers.

Definition at line 32 of file placement.c.

Referenced by game_advance_state(), interactive_placement(), and run_autonomous_mode().

◆ any_valid_placement_exists()

bool any_valid_placement_exists ( const Game game)
related

◆ validate_placement_simple()

bool validate_placement_simple ( const Game game,
Coords  target 
)
related

Definition at line 64 of file placement.c.

Referenced by any_valid_placement_exists(), and BotState::bot_compute_placement().

◆ validate_placement()

PlacementError validate_placement ( const Game game,
Coords  target 
)
related

Definition at line 70 of file placement.c.

Referenced by handle_placement_input(), and place_penguin().

◆ place_penguin()

void place_penguin ( Game game,
Coords  target 
)
related

Creates a GameLogPlacement entry. The requested placement must be valid.

Definition at line 93 of file placement.c.

Referenced by game_rewind_state_to_log_entry(), interactive_placement(), and run_autonomous_mode().

◆ undo_place_penguin()

void undo_place_penguin ( Game game)
related

Removes a GameLogPlacement entry from the log and undoes it.

Definition at line 115 of file placement.c.

Referenced by game_rewind_state_to_log_entry().


The documentation for this struct was generated from the following files: