Botball Game State
A game stared library for Botball, it helps model the table and different phases of the competition.
Loading...
Searching...
No Matches
Phase.h
1#pragma once
2#include <string>
3#include "TableState.h"
4using namespace Util;
5
9enum PhaseStatus {
13 OPEN,
17 BLOCKED,
21 TIMEOUT,
25 DONE
26};
27
33inline std::string statusCodeToString(const PhaseStatus status) {
34 switch (status) {
35 case OPEN:
36 return "OPEN";
37 case BLOCKED:
38 return "BLOCKED";
39 case TIMEOUT:
40 return "TIMEOUT";
41 case DONE:
42 return "DONE";
43 default:
44 throw std::logic_error("Unknown phase status");
45 }
46}
47
51class Phase {
52 int m_time_to_completion;
53 int m_points;
54 PhaseStatus m_status;
55 std::string m_id;
56 // Determines which bot "bot_a" or "bot_b" is allowed to execute this phase
57 std::string m_allowed_agent;
58 // key value pairs of strings to primitive datatypes representing if the phases conditions are met
59 std::unordered_map<std::string, std::any> m_conditions;
60 // key value pairs of strings to primitive datatypes which will be set in the table state after completion of the phase
61 std::unordered_map<std::string, std::any> m_completion;
62
63public:
64 explicit Phase(const std::string &phase_id, const json &data);
65
69 [[nodiscard]] const std::string get_id() const;
70
74 [[nodiscard]] int get_time_to_completion() const;
75
79 [[nodiscard]] const std::string &get_allowed_agent() const;
80
85 [[nodiscard]] const std::unordered_map<std::string, std::any> &get_conditions() const;
86
90 [[nodiscard]] const std::unordered_map<std::string, std::any> &get_completion() const;
91
95 [[nodiscard]] bool get_done() const;
96
101 [[nodiscard]] int get_points() const;
102
107 [[nodiscard]] PhaseStatus get_status() const;
108
113 void set_status(PhaseStatus status);
114
120 void set_status(PhaseStatus status, const Socket &so);
121
128 void execute(TableState &table, const std::function<void()> &action, const Socket &so);
129
130 std::string to_string() const;
131};
const std::unordered_map< std::string, std::any > & get_conditions() const
const std::string & get_allowed_agent() const
void set_status(PhaseStatus status, const Socket &so)
const std::string get_id() const
int get_points() const
PhaseStatus get_status() const
int get_time_to_completion() const
void set_status(PhaseStatus status)
bool get_done() const
void execute(TableState &table, const std::function< void()> &action, const Socket &so)
const std::unordered_map< std::string, std::any > & get_completion() const
Definition Socket.h:8
Definition TableState.h:6