penguins
1.0.0
|
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.
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:
When working in C++, it is possible to have this struct automatically managed with the help of a unique_ptr
:
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 | |
Player * | players |
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... | |
GameLogEntry * | 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. 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... | |
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... | |
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... | |
GamePhase Game::phase |
The current state of the state machine, initially set to GAME_PHASE_NONE. Use game_set_phase for setting this.
Definition at line 242 of file game.h.
Referenced by move_penguin(), movement_begin(), movement_end(), movement_switch_player(), CanvasPanel::paint_board(), place_penguin(), placement_begin(), placement_end(), placement_switch_player(), setup_board(), undo_move_penguin(), undo_place_penguin(), and PlayerInfoBox::update_data().
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().
int Game::players_count |
Use game_set_players_count for setting this.
Definition at line 251 of file game.h.
Referenced by game_clone(), GameEndDialog::GameEndDialog(), GamePanel::GamePanel(), movement_switch_player(), placement_switch_player(), print_player_stats(), run_autonomous_mode(), and save_game_state().
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().
int Game::current_player_index |
A negative value means that there is no current player selected. Use game_set_current_player for setting this.
Definition at line 256 of file game.h.
Referenced by display_new_turn_message(), GamePanel::get_controller_for_current_turn(), CanvasPanel::get_selected_penguin_coords(), handle_placement_input(), move_penguin(), movement_switch_player(), place_penguin(), placement_switch_player(), run_autonomous_mode(), undo_move_penguin(), undo_place_penguin(), and PlayerInfoBox::update_data().
int Game::board_width |
Use setup_board for setting this.
Definition at line 264 of file game.h.
Referenced by any_valid_placement_exists(), BotState::bot_compute_placement(), BotState::bot_flood_fill_check(), BotState::bot_flood_fill_mark(), game_clone(), generate_board_island(), generate_board_random(), CanvasPanel::get_canvas_size(), get_tile(), get_tile_attr(), is_tile_in_bounds(), load_game_state(), CanvasPanel::on_paint(), CanvasPanel::paint_board(), CanvasPanel::paint_tiles(), print_board(), save_game_state(), set_all_tiles_attr(), set_tile(), set_tile_attr(), setup_board(), PlayerPlacementController::update_tile_attributes(), and PlayerMovementController::update_tile_attributes().
int Game::board_height |
Use setup_board for setting this.
Definition at line 266 of file game.h.
Referenced by any_valid_placement_exists(), BotState::bot_compute_placement(), BotState::bot_flood_fill_check(), game_clone(), generate_board_island(), generate_board_random(), CanvasPanel::get_canvas_size(), is_tile_in_bounds(), load_game_state(), CanvasPanel::on_paint(), CanvasPanel::paint_board(), CanvasPanel::paint_tiles(), print_board(), save_game_state(), set_all_tiles_attr(), setup_board(), PlayerPlacementController::update_tile_attributes(), and PlayerMovementController::update_tile_attributes().
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:
It will be laid out in memory like this:
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.
The tiles themselves are encoded as integers in the following way:
n = 0
- a water tile.n = 1, 2, 3, ...
- an ice tile with n
fish.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().
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.
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().
bool Game::log_disabled |
Signals whether new log entries can be created. See game_push_log_entry.
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.
Definition at line 343 of file game.h.
Referenced by game_clone().
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().
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().
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.
|
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().
|
related |
Checks if the given coords
are within the bounds of the board.
Definition at line 70 of file board.h.
Referenced by BotState::bot_quick_junction_check(), BotState::bot_rate_move(), BotState::bot_rate_moves_list(), BotState::bot_rate_placement(), calculate_penguin_possible_moves(), count_obstructed_directions(), generate_board_island(), get_tile(), get_tile_attr(), set_tile(), set_tile_attr(), validate_movement(), validate_movement_start(), and validate_placement().
|
related |
Checks whether the attribute attr
of the tile at coords
is set.
|
related |
Sets (or resets) the attribute attr
of the tile at coords
.
Definition at line 86 of file board.h.
Referenced by set_all_tiles_attr(), and set_tile().
|
related |
Sets the attribute attr
on all tiles.
Definition at line 95 of file board.h.
Referenced by setup_board().
|
related |
Returns the value of the tile at coords
. Fails if coords
are outside the bounds.
Definition at line 108 of file board.h.
Referenced by BotState::bot_quick_junction_check(), BotState::bot_rate_move(), BotState::bot_rate_placement(), calculate_penguin_possible_moves(), count_obstructed_directions(), load_game_state(), move_penguin(), place_penguin(), print_board(), save_game_state(), test_move_penguin_and_calculate_points(), validate_movement(), validate_movement_start(), validate_placement(), and validate_placement_simple().
|
related |
Sets the value of the tile at coords
(and also sets the attribute TILE_DIRTY). Fails if coords
are outside the bounds.
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().
|
related |
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 run_autonomous_mode(), run_interactive_mode(), test_detect_valid_movement(), test_game_clone(), test_move_penguin_and_calculate_points(), test_movement_over_empty_space_invalid(), test_movement_over_penguin_invalid(), test_no_valid_movement_exists_for_player(), test_placeable_spot_does_not_exist(), test_placeable_spot_exists(), and test_valid_movement_exists_for_player().
Creates a (deep) copy of another Game.
Definition at line 36 of file game.c.
Referenced by test_game_clone().
|
related |
Destroys a Game, freeing the memory allocated for the struct itself and all associated internal lists.
Definition at line 68 of file game.c.
Referenced by run_autonomous_mode(), run_interactive_mode(), test_detect_valid_movement(), test_game_clone(), test_move_penguin_and_calculate_points(), test_movement_over_empty_space_invalid(), test_movement_over_penguin_invalid(), test_no_valid_movement_exists_for_player(), test_placeable_spot_does_not_exist(), test_placeable_spot_exists(), and test_valid_movement_exists_for_player().
|
related |
|
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().
|
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.
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().
|
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().
|
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().
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().
|
related |
Sets Game::current_player_index and creates a GameLogPlayerChange log entry.
Definition at line 195 of file game.c.
Referenced by game_end(), movement_begin(), movement_switch_player(), placement_begin(), placement_switch_player(), test_detect_valid_movement(), test_move_penguin_and_calculate_points(), test_movement_over_empty_space_invalid(), and test_movement_over_penguin_invalid().
|
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().
|
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:
Definition at line 224 of file game.c.
Referenced by game_advance_state(), run_autonomous_mode(), run_interactive_mode(), and setup_test_game().
|
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().
|
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().
|
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().
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().
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().
|
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.
|
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().
|
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.
|
related |
Checks if idx
is within the bounds of Game::players.
Definition at line 387 of file game.h.
Referenced by game_get_player().
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 any_valid_player_move_exists(), game_add_player_penguin(), game_find_player_penguin(), game_get_current_player(), game_remove_player_penguin(), game_set_player_name(), load_game_state(), placement_switch_player(), print_board(), print_player_stats(), run_autonomous_mode(), run_interactive_mode(), save_game_state(), setup_test_game(), and test_move_penguin_and_calculate_points().
A shorthand for calling game_get_player with Game::current_player_index.
Definition at line 401 of file game.h.
Referenced by BotState::bot_compute_move(), BotState::bot_rate_move(), BotState::bot_rate_placement(), display_new_turn_message(), move_penguin(), place_penguin(), undo_move_penguin(), undo_place_penguin(), validate_movement_start(), and validate_placement().
|
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().
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().
|
related |
Enters the GAME_PHASE_MOVEMENT phase, can only be called in GAME_PHASE_SETUP_DONE.
Definition at line 11 of file movement.c.
Referenced by game_advance_state(), interactive_movement(), run_autonomous_mode(), and test_move_penguin_and_calculate_points().
|
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().
|
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().
|
related |
Definition at line 47 of file movement.c.
Referenced by movement_switch_player(), test_no_valid_movement_exists_for_player(), and test_valid_movement_exists_for_player().
|
related |
Definition at line 58 of file movement.c.
Referenced by handle_movement_input(), and validate_movement().
|
related |
Definition at line 76 of file movement.c.
Referenced by handle_movement_input(), move_penguin(), test_detect_valid_movement(), test_movement_over_empty_space_invalid(), and test_movement_over_penguin_invalid().
Creates a GameLogMovement entry. The requested move must be valid.
Definition at line 118 of file movement.c.
Referenced by BotState::bot_rate_move(), game_rewind_state_to_log_entry(), interactive_movement(), run_autonomous_mode(), and test_move_penguin_and_calculate_points().
|
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().
Definition at line 50 of file movement.h.
Referenced by any_valid_player_move_exists(), BotState::bot_rate_move(), BotState::bot_rate_placement(), and validate_movement_start().
|
related |
Definition at line 64 of file movement.h.
Referenced by BotState::bot_generate_all_moves_list().
|
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().
|
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().
|
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().
|
related |
Definition at line 51 of file placement.c.
Referenced by placement_switch_player(), test_placeable_spot_does_not_exist(), and test_placeable_spot_exists().
Definition at line 64 of file placement.c.
Referenced by any_valid_placement_exists(), and BotState::bot_compute_placement().
|
related |
Definition at line 70 of file placement.c.
Referenced by handle_placement_input(), and place_penguin().
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().
|
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().