Botball Game State
A game stared library for Botball, it helps model the table and different phases of the competition.
Loading...
Searching...
No Matches
GameState Class Reference

#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>
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)

Detailed Description

Main Application of the competition code
Responsible for the lifecycle

  1. Parse Config files
  2. Either listen to or connect to the other bot to synchronize the game state between both of them
  3. Run the application, choose phase execute transition...
  4. Close all open resources, and write detailed info about the run into logfiles

Constructor & Destructor Documentation

◆ GameState() [1/2]

GameState::GameState ( TableState table_state,
const Config & config,
PhaseState phase_state )
Parameters
table_state
config
phase_state

◆ GameState() [2/2]

GameState::GameState ( GameState && other)
noexcept

Not implemented, declaration necessary so the class can hold a mutex

Parameters
other

Member Function Documentation

◆ connect_client()

GameState GameState::connect_client ( const std::string & ip,
uint16_t port )
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.

Parameters
ipspecifies ip address of bot_a (only for client)
portspecifies port of bot_a (only for client)
Returns
the reconstructed game state

◆ connect_server()

GameState GameState::connect_server ( const std::string & game_state_config_path,
const std::string & table_state_config_path,
const std::string & phase_state_config_path )
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

Parameters
table_state_config_pathpath to table state config file on bot_a (server)
game_state_config_pathpath to game state config file on bot_a (server)
phase_state_config_pathpath to phase_state_config_path on bot_a (server)
Returns
the game state parsed from the config files

◆ mutate_shared_state()

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.

  • This method performs a thread-safe update of the local GameTableModel and immediately broadcasts the change to the connected peer via the network socket.
  • Note
    This method acquires a lock on m_state_mutex to ensure consistency between the local model and the data sent over the wire.
  • Parameters
    keyThe unique string identifier for the state variable (e.g., "collected_data").
    valueThe data to store, wrapped in a std::any. Ensure the type matches the expected type in the TableState configuration.

◆ read_shared_state()

template<typename T>
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

  • double
  • int
  • bool
  • std::string
  • std::vector<double>
  • std::vector<int>
  • std::vector<bool>
  • std::vector<string>
    Template Parameters
    Ttype of the desired value
    Parameters
    keykey holding the desired value
    Returns
    desired value

◆ run()

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.

Parameters
actionsa registry of all functions, each phase needs to have a corresponding function

The documentation for this class was generated from the following file: