Grail (C++)  1.2.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
ISimulatedGameUnit.hh
1 // Copyright QED Software 2023.
2 
3 #ifndef GRAIL_SIMULATED_GAME_UNIT
4 #define GRAIL_SIMULATED_GAME_UNIT
5 
6 #include <list>
7 #include <map>
8 #include <memory>
9 #include <random>
10 #include <string>
11 #include <vector>
12 #include "ISimulatedGameAction.hh"
13 #include "ISimulatedGameHeuristic.hh"
14 
15 namespace grail
16 {
17 namespace simgames
18 {
19  using RandomGenerator = std::mt19937_64;
20 
21  class SimulatedGameNode;
22 
29  {
30  public:
31  virtual ~ISimulatedGameUnit();
32 
36  virtual void Reset() = 0;
37 
41  virtual int GetTeamIndex() const = 0;
47  virtual std::vector<std::unique_ptr<const ISimulatedGameAction>> GetAvailableActions() const = 0;
48 
56  virtual std::unique_ptr<const ISimulatedGameAction> GetRandomAvailableAction(
57  RandomGenerator& rand_gen) const;
58 
63  virtual void AfterAction(SimulatedGameRuntime&);
64 
68  virtual std::string ToString() const;
69 
74  virtual void FillDebugRepresentation(std::map<std::string, std::string>& nameValueDictionary) const;
79  std::vector<std::unique_ptr<SimulatedGameHeuristic>> heuristicReasoners;
80  private:
82  virtual void ObserveNode(const SimulatedGameNode*);
83 
85  virtual bool IsStochastic() const = 0;
86 
87  friend class SimulatedGame;
88  friend class SimulatedGameNode;
89  };
90 }
91 }
92 
93 #endif //GRAIL_SIMULATED_GAME_UNIT
grail::simgames::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:79
grail::simgames::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:24
grail::simgames::SimulatedGameRuntime
An interface that is used to terminate simulation in MCTS and set scores to players....
Definition: SimulatedGameRuntime.hh:17
grail::simgames::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:15
grail::simgames::SimulatedGame
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm....
Definition: SimulatedGame.hh:30
grail::simgames::ISimulatedGameUnit::ToString
virtual std::string ToString() const
Returns the text representation of the unit for debugging purposes. Default implementation returns an...
Definition: ISimulatedGameUnit.cpp:19
grail::simgames::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:9
grail::simgames::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::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::simgames::ISimulatedGameUnit::Reset
virtual void Reset()=0
Resets state of the unit to the beginning of the SimulatedGame.
grail::simgames::ISimulatedGameUnit::GetAvailableActions
virtual std::vector< std::unique_ptr< const ISimulatedGameAction > > GetAvailableActions() const =0
Returns the actions the unit may perform. It is strongly advised to create a new vector here,...
grail::simgames::SimulatedGameNode
This class should not be visible to developers at all.
Definition: SimulatedGameNode.h:25