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