(C++)  1.0.0
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 "ISimulatedGameAction.hh"
5 #include "ISimulatedGameHeuristic.hh"
6 #include <random>
7 #include <vector>
8 #include <list>
9 #include <memory>
10 #include <string>
11 #include <map>
12 
13 namespace grail
14 {
15  typedef std::mt19937_64 RandomGenerator;
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(RandomGenerator& rand_gen) const;
55 
60  virtual void AfterAction(SimulatedGameRuntime&);
61 
65  virtual std::string ToString() const;
66 
71  virtual void FillDebugRepresentation(std::map<std::string, std::string>& nameValueDictionary) const;
76  std::vector<std::unique_ptr<SimulatedGameHeuristic>> heuristicReasoners;
77  private:
79  virtual void ObserveNode(const SimulatedGameNode*);
80 
82  virtual bool IsStochastic() const = 0;
83 
84  friend class SimulatedGame;
85  friend class SimulatedGameNode;
86  };
87  }
88 }
89 #endif //GRAIL_SIMULATED_GAME_UNIT
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:27
virtual std::vector< std::unique_ptr< const ISimulatedGameAction > > GetAvailableActions() const =0
Returns the actions the unit may perform.
virtual void Reset()=0
Resets state of the unit to the beginning of the SimulatedGame.
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:3
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:76
virtual int GetTeamIndex() const =0
Returns the index of a team. Units with the same team index share the same game score.
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
virtual std::string ToString() const
Returns the text representation of the unit for debugging purposes. Default implementation returns an...
Definition: ISimulatedGameUnit.cpp:14
virtual void AfterAction(SimulatedGameRuntime &)
This method is called after action.Apply(). You may insert custom logic here - for example - code tha...
Definition: ISimulatedGameUnit.cpp:9
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm....
Definition: SimulatedGame.hh:29
This class should not be visible to developers at all.
Definition: SimulatedGameNode.h:24
An interface that is used to terminate simulation in MCTS and set scores to players....
Definition: SimulatedGameRuntime.hh:16