Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
SimulatedGamesSnapshots.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SIMULATED_GAMES_SNAPSHOTS_H
4 #define GRAIL_SIMULATED_GAMES_SNAPSHOTS_H
5 
6 #include "Flatbuffers/SimulatedGameUnitSnapshot_generated.h"
7 #include "Flatbuffers/SimulatedGameActionMetadataSnapshot_generated.h"
8 #include "Flatbuffers/SimulatedGameMonteCarloEventSnapshot_generated.h"
9 #include "Flatbuffers/SimulatedGameUCTEventSnapshot_generated.h"
10 #include "Flatbuffers/SimulatedGameIterationSnapshot_generated.h"
11 #include "Flatbuffers/SimulatedGameReasonerSnapshot_generated.h"
12 
13 #include <map>
14 #include <string>
15 #include <unordered_map>
16 #include <vector>
17 
18 namespace grail
19 {
20  namespace simgames
21  {
22  class ISimulatedGameUnit;
23  }
24 
25 namespace data
26 {
30  {
32  int teamIndex = 0;
33 
35  int orderID = 0;
36 
38  std::string description = "";
39 
41  std::map<std::string, std::string> state = {};
42 
44  SimulatedGameUnitSnapshot() = default;
45  };
46 
47  flatbuffers::Offset<generated::SimulatedGameUnitSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
48  const SimulatedGameUnitSnapshot& snapshot);
49  SimulatedGameUnitSnapshot Unpack(const generated::SimulatedGameUnitSnapshot& snapshot);
50 
54  {
56  double score = 0;
57 
59  int visits = 0;
60 
62  std::string actionDescription = "";
63 
64  SimulatedGameActionMetadataSnapshot(double score, int visits, const std::string& description);
66  };
67 
68  flatbuffers::Offset<generated::SimulatedGameActionMetadataSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
69  const SimulatedGameActionMetadataSnapshot& snapshot);
70  SimulatedGameActionMetadataSnapshot Unpack(const generated::SimulatedGameActionMetadataSnapshot& snapshot);
71 
75  {
77  std::string chosenActionDescription = {};
78 
80  std::vector<SimulatedGameUnitSnapshot> unitSnapshots = {};
81  int activeUnitUID = 0;
82 
85  };
86 
87  flatbuffers::Offset<generated::SimulatedGameMonteCarloEventSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
88  const SimulatedGameMonteCarloEventSnapshot& snapshot);
89  SimulatedGameMonteCarloEventSnapshot Unpack(const generated::SimulatedGameMonteCarloEventSnapshot& snapshot);
90 
94  {
95  std::vector<SimulatedGameActionMetadataSnapshot> actionMetadataSnapshots = {};
98  };
99 
100  flatbuffers::Offset<generated::SimulatedGameUCTEventSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
101  const SimulatedGameUCTEventSnapshot& snapshot);
102  SimulatedGameUCTEventSnapshot Unpack(const generated::SimulatedGameUCTEventSnapshot& snapshot);
103 
107  {
108  size_t number = 0;
109 
111  std::vector<SimulatedGameUCTEventSnapshot> uctSnapshots = {};
112 
114  std::vector<SimulatedGameMonteCarloEventSnapshot> monteCarloSnapshots = {};
115 
117  std::vector<float> scores = {};
118 
120  void Clear();
121  };
122 
123  flatbuffers::Offset<generated::SimulatedGameIterationSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
124  const SimulatedGameIterationSnapshot& snapshot);
125  SimulatedGameIterationSnapshot Unpack(const generated::SimulatedGameIterationSnapshot& snapshot);
126 
130  {
132  std::vector<SimulatedGameUnitSnapshot> unitSnapshots = {};
133 
135  std::vector<SimulatedGameIterationSnapshot> iterationSnapshots = {};
136 
137  float absoluteTime = 0;
138  float relativeTime = 0;
139  size_t entityId = 0;
140  };
141 
142  flatbuffers::Offset<generated::SimulatedGameReasonerSnapshot> Pack(flatbuffers::FlatBufferBuilder& builder,
143  const SimulatedGameReasonerSnapshot& snapshot);
144  SimulatedGameReasonerSnapshot Unpack(const generated::SimulatedGameReasonerSnapshot& snapshot);
145 }
146 }
147 
148 #endif //GRAIL_SIMULATED_GAMES_SNAPSHOTS_H
grail::data::SimulatedGameIterationSnapshot::monteCarloSnapshots
std::vector< SimulatedGameMonteCarloEventSnapshot > monteCarloSnapshots
Events that happened during the iteration in the Monte Carlo (simulation) phase.
Definition: SimulatedGamesSnapshots.h:114
grail::data::SimulatedGameMonteCarloEventSnapshot
Definition: SimulatedGamesSnapshots.h:74
grail::data::SimulatedGameIterationSnapshot::scores
std::vector< float > scores
Scores achieved by teams at the end of the iteration.
Definition: SimulatedGamesSnapshots.h:117
grail::data::SimulatedGameIterationSnapshot::Clear
void Clear()
Clears all the stored data.
Definition: SimulatedGamesSnapshots.cpp:29
grail::data::SimulatedGameUnitSnapshot
Definition: SimulatedGamesSnapshots.h:29
grail::data::SimulatedGameReasonerSnapshot::iterationSnapshots
std::vector< SimulatedGameIterationSnapshot > iterationSnapshots
Snapshots of iterations contained in the SimulatedGameSnapshot.
Definition: SimulatedGamesSnapshots.h:135
grail::data::SimulatedGameUnitSnapshot::description
std::string description
Display text for the unit in logs and GUI tool.
Definition: SimulatedGamesSnapshots.h:38
grail::data::SimulatedGameActionMetadataSnapshot::actionDescription
std::string actionDescription
Text representation of the action.
Definition: SimulatedGamesSnapshots.h:62
grail::data::SimulatedGameReasonerSnapshot
Definition: SimulatedGamesSnapshots.h:129
grail::data::SimulatedGameMonteCarloEventSnapshot::unitSnapshots
std::vector< SimulatedGameUnitSnapshot > unitSnapshots
States of units after action was performed.
Definition: SimulatedGamesSnapshots.h:80
grail::data::SimulatedGameUnitSnapshot::teamIndex
int teamIndex
The "owning" player. Units of the same team should share the same color in the GUI tool.
Definition: SimulatedGamesSnapshots.h:32
grail::data::SimulatedGameUCTEventSnapshot
Definition: SimulatedGamesSnapshots.h:93
grail::data::SimulatedGameUnitSnapshot::state
std::map< std::string, std::string > state
State of the unit as serialized by FillDebugRepresentation method of a unit.
Definition: SimulatedGamesSnapshots.h:41
grail::data::SimulatedGameActionMetadataSnapshot::score
double score
Quality of the action.
Definition: SimulatedGamesSnapshots.h:56
grail::simgames::ISimulatedGameUnit
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:28
grail::data::SimulatedGameIterationSnapshot
Definition: SimulatedGamesSnapshots.h:106
grail::data::SimulatedGameActionMetadataSnapshot::visits
int visits
The number of visits of the action = how many times it was sampled in iterations.
Definition: SimulatedGamesSnapshots.h:59
grail::data::SimulatedGameMonteCarloEventSnapshot::chosenActionDescription
std::string chosenActionDescription
The action performed by the active unit.
Definition: SimulatedGamesSnapshots.h:77
grail::data::SimulatedGameActionMetadataSnapshot
Definition: SimulatedGamesSnapshots.h:53
grail::data::SimulatedGameIterationSnapshot::uctSnapshots
std::vector< SimulatedGameUCTEventSnapshot > uctSnapshots
Events that happened during the iteration in the UCT (selection) phase.
Definition: SimulatedGamesSnapshots.h:111
grail::data::SimulatedGameUnitSnapshot::orderID
int orderID
Ordered unique identifier of the unit. In this order they will apear in the GUI tool.
Definition: SimulatedGamesSnapshots.h:35
grail::data::SimulatedGameReasonerSnapshot::unitSnapshots
std::vector< SimulatedGameUnitSnapshot > unitSnapshots
Units that took part in the game.
Definition: SimulatedGamesSnapshots.h:132