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.h
1#pragma once
2#include <thread>
3#include "Util.h"
4#include "PhaseState.h"
5#include "Socket.h"
6#include "TableState.h"
7using namespace Util;
8
12struct Config {
16 double Kp;
20 double Kt;
24 double Kpt;
25};
26
35class GameState {
36 std::unique_ptr<Socket> m_socket = nullptr;
37 Config m_config{};
38 std::thread m_listen_thread;
39 TableState m_game_table;
40 PhaseState m_phase_state;
41 std::string m_agent;
42 std::shared_ptr<spdlog::logger> m_log;
43 mutable std::mutex m_state_mutex;
44 std::atomic<bool> m_listening{false};
45 std::chrono::steady_clock::time_point m_game_start;
46
51 [[nodiscard]] bool has_phases() const;
52
53
54 [[nodiscard]] std::optional<std::string> get_next_best_phase();
55
64 [[nodiscard]] double compute_potential(const Phase &phase_candidate) const;
65
73 void update_phase_status(Phase &phase) const;
74
78 [[nodiscard]] int time_remaining() const;
79
84 void listen();
85
90 void execute_init(const std::function<void()> &action);
91
92public:
99 GameState(TableState table_state, const Config &config, PhaseState phase_state);
100
105 GameState(GameState &&other) noexcept;
106
114 [[nodiscard]] static GameState connect_server(const std::string &game_state_config_path,
115 const std::string &table_state_config_path,
116 const std::string &phase_state_config_path);
117
124 [[nodiscard]] static GameState connect_client(const std::string &ip, uint16_t port);
125
130 void run(const std::unordered_map<std::string, std::function<void()> > &actions);
131
142 void mutate_shared_state(const std::string &key, std::any value);
143
158 template<typename T>
159 T read_shared_state(const std::string &key) const;
160};
void run(const std::unordered_map< std::string, std::function< void()> > &actions)
GameState(GameState &&other) noexcept
static GameState connect_client(const std::string &ip, uint16_t port)
void mutate_shared_state(const std::string &key, std::any value)
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)
T read_shared_state(const std::string &key) const
GameState(TableState table_state, const Config &config, PhaseState phase_state)
Definition Phase.h:51
Definition PhaseState.h:5
Definition TableState.h:6
Definition GameState.h:12
double Kt
Definition GameState.h:20
double Kp
Definition GameState.h:16
double Kpt
Definition GameState.h:24