Grail (C++)  1.4.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:
30 
34  bool IsInitialized() const;
35 
36  void OnGameStart(const std::vector<std::shared_ptr<SimulatedGameThinkingUnit>>& thinkingUnits,
37  const std::vector<std::shared_ptr<SimulatedGameStochasticUnit>>& stochasticUnits);
38  void OnIterationStart(size_t iterationNumber);
39  void OnUCTAction(const ISimulatedGameAction& chosenAction, const SimulatedGameNode& node);
40  void OnMonteCarloAction(const ISimulatedGameAction& chosenAction, const ISimulatedGameUnit& activeUnit);
41  void OnIterationEnd(const std::vector<double>& scores);
42 
46  void SetMinIteration(size_t iteration);
47 
51  size_t GetMinIteration() const;
52 
56  void SetMaxIteration(size_t iteration);
57 
61  size_t GetMaxIteration() const;
62 
63  private:
64  int GetUnitUID(const ISimulatedGameUnit* unit);
65 
67  data::SimulatedGameIterationSnapshot currentIteration;
68  std::unordered_map<const ISimulatedGameUnit*, int> idMap = {};
69  bool isInitialized = false;
70  size_t minIteration = 0;
71  size_t maxIteration = std::numeric_limits<size_t>::max();
72  unsigned long globalIterationIndex = 0;
73  };
74 }
75 }
76 #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