|
Botball Game State
A game stared library for Botball, it helps model the table and different phases of the competition.
|
#include <GameState.h>
Public Member Functions | |
| GameState (TableState table_state, const Config &config, PhaseState phase_state) | |
| GameState (GameState &&other) noexcept | |
| void | run (const std::unordered_map< std::string, std::function< void()> > &actions) |
| void | mutate_shared_state (const std::string &key, std::any value) |
| template<typename T> | |
| T | read_shared_state (const std::string &key) const |
Static Public Member Functions | |
| static GameState | connect_server (const std::string &game_state_config_path, const std::string &table_state_config_path, const std::string &phase_state_config_path) |
| static GameState | connect_client (const std::string &ip, uint16_t port) |
Main Application of the competition code
Responsible for the lifecycle
| GameState::GameState | ( | TableState | table_state, |
| const Config & | config, | ||
| PhaseState | phase_state ) |
| table_state | |
| config | |
| phase_state |
|
noexcept |
Not implemented, declaration necessary so the class can hold a mutex
| other |
|
staticnodiscard |
bot_b calls this function and connects with the listening socket on bot_a, it sends a request for the game state which it receives as JSON and reconstructs it.
| ip | specifies ip address of bot_a (only for client) |
| port | specifies port of bot_a (only for client) |
|
staticnodiscard |
bot_a calls this function, listens for a request from bot_b and sends the (verified) game state as config file to bot_b
| table_state_config_path | path to table state config file on bot_a (server) |
| game_state_config_path | path to game state config file on bot_a (server) |
| phase_state_config_path | path to phase_state_config_path on bot_a (server) |
| void GameState::mutate_shared_state | ( | const std::string & | key, |
| std::any | value ) |
Updates a value in the shared game state and synchronizes it with the remote agent.
| key | The unique string identifier for the state variable (e.g., "collected_data"). |
| value | The data to store, wrapped in a std::any. Ensure the type matches the expected type in the TableState configuration. |
| T GameState::read_shared_state | ( | const std::string & | key | ) | const |
Gets a value from the table state for the bot to use, has to be
| T | type of the desired value |
| key | key holding the desired value |
| void GameState::run | ( | const std::unordered_map< std::string, std::function< void()> > & | actions | ) |
Starts by executing the bots init phases then calculates, executes and transitions between phases until all phases are done or timed out.
| actions | a registry of all functions, each phase needs to have a corresponding function |