Grail (C++)  1.3.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
SimulatedGameSnapshotObserver.h
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SIMULATED_GAME_SNAPSHOT_OBSERVER_H
4 #define GRAIL_SIMULATED_GAME_SNAPSHOT_OBSERVER_H
5 
6 #include <limits>
7 #include <memory>
8 #include <unordered_map>
9 #include <vector>
10 #include "SimulatedGameActionMetadata.hh"
11 #include "../GrailData/DebugInfo/SimulatedGamesSnapshots.h"
12 
13 namespace grail
14 {
15 namespace simgames
16 {
17  class SimulatedGameThinkingUnit;
18  class SimulatedGameStochasticUnit;
19  class ISimulatedGameAction;
20  class ISimulatedGameUnit;
21  class SimulatedGameNode;
22 
24  {
25  public:
28 
32  bool IsInitialized() const;
33 
34  void OnGameStart(const std::vector<std::shared_ptr<SimulatedGameThinkingUnit>>& thinkingUnits,
35  const std::vector<std::shared_ptr<SimulatedGameStochasticUnit>>& stochasticUnits);
36  void OnIterationStart(size_t iterationNumber);
37  void OnUCTAction(const ISimulatedGameAction& chosenAction, const SimulatedGameNode& node);
38  void OnMonteCarloAction(const ISimulatedGameAction& chosenAction, const ISimulatedGameUnit& activeUnit);
39  void OnIterationEnd(const std::vector<float>& scores);
40 
42  void SetMinIteration(size_t iteration);
43 
45  size_t GetMinIteration() const;
46 
48  void SetMaxIteration(size_t iteration);
49 
51  size_t GetMaxIteration() const;
52 
53  private:
54  int GetUnitUID(const ISimulatedGameUnit* unit);
55 
57  data::SimulatedGameIterationSnapshot currentIteration;
58  std::unordered_map<const ISimulatedGameUnit*, int> idMap = {};
59  bool isInitialized = false;
60  size_t minIteration = 0;
61  size_t maxIteration = std::numeric_limits<size_t>::max();
62  unsigned long globalIterationIndex = 0;
63  };
64 }
65 }
66 #endif //GRAIL_SIMULATED_GAME_SNAPSHOT_OBSERVER_H
grail::simgames::ISimulatedGameAction
Base class for all actions in SimulatedGame. Derive from it for your actions.
Definition: ISimulatedGameAction.hh:41
grail::data::SimulatedGameReasonerSnapshot
Definition: SimulatedGamesSnapshots.h:129
grail::simgames::SimulatedGameSnapshotObserver::GetSnapshot
data::SimulatedGameReasonerSnapshot & GetSnapshot()
Returns serialized snapshot of SimulatedGameReasoner.
Definition: SimulatedGameSnapshotObserver.cpp:13
grail::simgames::SimulatedGameSnapshotObserver
Definition: SimulatedGameSnapshotObserver.h:23
grail::simgames::SimulatedGameSnapshotObserver::SetMinIteration
void SetMinIteration(size_t iteration)
Sets the minimum number of iteration that will be gathered during the debugging.
Definition: SimulatedGameSnapshotObserver.cpp:23
grail::simgames::SimulatedGameSnapshotObserver::IsInitialized
bool IsInitialized() const
Returns true if the observer is initialized and ready to gather data.
Definition: SimulatedGameSnapshotObserver.cpp:18
grail::simgames::SimulatedGameSnapshotObserver::GetMaxIteration
size_t GetMaxIteration() const
Gets the maximum number of iteration that will be gathered during the debugging.
Definition: SimulatedGameSnapshotObserver.cpp:38
grail::simgames::SimulatedGameSnapshotObserver::SetMaxIteration
void SetMaxIteration(size_t iteration)
Sets the maximum number of iteration that will be gathered during the debugging.
Definition: SimulatedGameSnapshotObserver.cpp:33
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::simgames::SimulatedGameNode
This class should not be visible to developers at all.
Definition: SimulatedGameNode.hh:25
grail::simgames::SimulatedGameSnapshotObserver::GetMinIteration
size_t GetMinIteration() const
Gets the minimum number of iteration that will be gathered during the debugging.
Definition: SimulatedGameSnapshotObserver.cpp:28