Grail (C++)  1.1.1
A multi-platform, modular, universal engine for embedding advanced AI in games.
ISimulatedGameUnit.hh
1 #ifndef GRAIL_SIMULATED_GAME_UNIT
2 #define GRAIL_SIMULATED_GAME_UNIT
3 
4 #include <list>
5 #include <map>
6 #include <memory>
7 #include <random>
8 #include <string>
9 #include <vector>
10 #include "ISimulatedGameAction.hh"
11 #include "ISimulatedGameHeuristic.hh"
12 
13 namespace grail
14 {
15  using RandomGenerator = std::mt19937_64;
16 
17  namespace simulation
18  {
19  class SimulatedGameNode;
20 
27  {
28  public:
29  virtual ~ISimulatedGameUnit();
30 
34  virtual void Reset() = 0;
35 
39  virtual int GetTeamIndex() const = 0;
42  // It is strongly advised to create a new vector here, return it and no longer use it. It will be stored in the SimulatedGame structures.
45  virtual std::vector<std::unique_ptr<const ISimulatedGameAction>> GetAvailableActions() const = 0;
46 
54  virtual std::unique_ptr<const ISimulatedGameAction> GetRandomAvailableAction(
55  RandomGenerator& rand_gen) const;
56 
61  virtual void AfterAction(SimulatedGameRuntime&);
62 
66  virtual std::string ToString() const;
67 
72  virtual void FillDebugRepresentation(std::map<std::string, std::string>& nameValueDictionary) const;
77  std::vector<std::unique_ptr<SimulatedGameHeuristic>> heuristicReasoners;
78  private:
80  virtual void ObserveNode(const SimulatedGameNode*);
81 
83  virtual bool IsStochastic() const = 0;
84 
85  friend class SimulatedGame;
86  friend class SimulatedGameNode;
87  };
88  }
89 }
90 #endif //GRAIL_SIMULATED_GAME_UNIT
grail::simulation::ISimulatedGameUnit::ToString
virtual std::string ToString() const
Returns the text representation of the unit for debugging purposes. Default implementation returns an...
Definition: ISimulatedGameUnit.cpp:14
grail::simulation::ISimulatedGameUnit::FillDebugRepresentation
virtual void FillDebugRepresentation(std::map< std::string, std::string > &nameValueDictionary) const
Method used to gather data for GUI-based debugging. Insert properties of the state (key,...
Definition: ISimulatedGameUnit.cpp:19
grail::simulation::ISimulatedGameUnit::Reset
virtual void Reset()=0
Resets state of the unit to the beginning of the SimulatedGame.
grail::simulation::ISimulatedGameUnit::heuristicReasoners
std::vector< std::unique_ptr< SimulatedGameHeuristic > > heuristicReasoners
Add or remove heuristic. See @SimulatedGameHeuristic. Heuristic is used to provide the action to play...
Definition: ISimulatedGameUnit.hh:77
grail::simulation::SimulatedGameNode
This class should not be visible to developers at all.
Definition: SimulatedGameNode.h:23
grail::simulation::ISimulatedGameUnit::GetRandomAvailableAction
virtual std::unique_ptr< const ISimulatedGameAction > GetRandomAvailableAction(RandomGenerator &rand_gen) const
Returns a random action to be chosen in simulation. The default implementation samples from GetAvaila...
Definition: ISimulatedGameUnit.cpp:4
grail::simulation::SimulatedGame
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm....
Definition: SimulatedGame.hh:28
grail::simulation::ISimulatedGameUnit::GetTeamIndex
virtual int GetTeamIndex() const =0
Returns the index of a team. Units with the same team index share the same game score.
grail::simulation::SimulatedGameRuntime
An interface that is used to terminate simulation in MCTS and set scores to players....
Definition: SimulatedGameRuntime.hh:15
grail::simulation::ISimulatedGameUnit::GetAvailableActions
virtual std::vector< std::unique_ptr< const ISimulatedGameAction > > GetAvailableActions() const =0
Returns the actions the unit may perform.
grail::simulation::ISimulatedGameUnit::AfterAction
virtual void AfterAction(SimulatedGameRuntime &)
This method is called after action.Apply(). You may insert custom logic here - for example - code tha...
Definition: ISimulatedGameUnit.cpp:10
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