|
Grail (C++)
1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
3 #ifndef GRAIL_SIMULATED_GAME_H
4 #define GRAIL_SIMULATED_GAME_H
6 #include "ISimulatedGameUnit.hh"
7 #include "SimulatedGameActionMetadata.hh"
8 #include "SimulatedGameNode.hh"
9 #include "SimulatedGameHelper.h"
10 #include "SimulatedGameSnapshotObserver.h"
14 #include <unordered_map>
21 class SimulatedGameThinkingUnit;
22 class SimulatedGameStochasticUnit;
23 class ISimulatedGameAction;
24 class SimulatedGameNode;
43 double maxScore = 1.0,
44 double explorationBoost = 1.0,
45 size_t freezeVisitsTreshold = std::numeric_limits<size_t>::max(),
46 RandomGenerator::result_type seed = std::random_device{}());
59 void AddUnits(std::vector<std::shared_ptr<SimulatedGameThinkingUnit>> units);
94 std::vector<std::pair<const ISimulatedGameUnit*, const ISimulatedGameAction*>>
GetExpectedPlayout()
const;
107 std::unordered_map<const ISimulatedGameUnit*, std::vector<const ISimulatedGameAction*>>
GetExpectedPlans();
113 std::unordered_map<const ISimulatedGameUnit*, std::vector<SimulatedGameActionMetadata>>
124 virtual size_t Run(
size_t milisecondsTotal,
125 size_t maxIterationCount,
129 std::unordered_map<
const ISimulatedGameUnit*, std::vector<const ISimulatedGameAction*>>& plan)
const;
130 void DebugPrintPlanWithMetadata(
131 std::unordered_map<
const ISimulatedGameUnit*, std::vector<SimulatedGameActionMetadata>>& plan)
const;
132 void DebugPrintFullPlayout(
133 std::vector<std::pair<const ISimulatedGameUnit*, const ISimulatedGameAction*>>& playout)
const;
154 std::vector<std::shared_ptr<SimulatedGameThinkingUnit>> thinkingUnits{};
155 std::vector<std::shared_ptr<SimulatedGameStochasticUnit>> stochasticUnits{};
157 RandomGenerator rand_gen{};
158 std::unique_ptr<SimulatedGameNode> rootNode{};
165 #endif //GRAIL_SIMULATED_GAME_H
SimulatedGameThinkingUnit & AddUnit(std::shared_ptr< SimulatedGameThinkingUnit > unit)
Adds a new regular unit to the game.
Definition: SimulatedGame.cpp:225
const SimulatedGameActionMetadata GetStartingUnitBestActionMetadata() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:293
std::unordered_map< const ISimulatedGameUnit *, std::vector< const ISimulatedGameAction * > > GetExpectedPlans()
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:310
void SetStartingUnit(SimulatedGameThinkingUnit &unit)
Gets or sets the unit that acts first in the starting state of the game.
Definition: SimulatedGame.cpp:91
A base class of a unit in SimulatedGame that peforms actions according to some probability distributi...
Definition: SimulatedGameStochasticUnit.hh:23
Definition: SimulatedGameHelper.h:18
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm....
Definition: SimulatedGame.hh:30
Base class for all actions in SimulatedGame. Derive from it for your actions.
Definition: ISimulatedGameAction.hh:41
A base class of a unit related to a rational/intelligent player. MCTS chooses actions for this kind o...
Definition: SimulatedGameThinkingUnit.hh:23
SimulatedGame(int teamCount=2, double maxScore=1.0, double explorationBoost=1.0, size_t freezeVisitsTreshold=std::numeric_limits< size_t >::max(), RandomGenerator::result_type seed=std::random_device{}())
Constructs a new SimulatedGame object. This object can be reused.
Definition: SimulatedGame.cpp:195
Definition: SimulatedGameSnapshotObserver.h:23
std::vector< std::pair< const ISimulatedGameUnit *, const ISimulatedGameAction * > > GetExpectedPlayout() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:299
void ClearStatistics()
This method invalidates the tree built for the game. If any offline learners were attached,...
Definition: SimulatedGame.cpp:96
void AddUnits(std::vector< std::shared_ptr< SimulatedGameThinkingUnit >> units)
Adds new regular units to the game.
Definition: SimulatedGame.cpp:275
std::unordered_map< const ISimulatedGameUnit *, std::vector< SimulatedGameActionMetadata > > GetExpectedPlansWithMetadata()
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:321
virtual size_t Run(size_t milisecondsTotal, size_t maxIterationCount, SimulatedGameSnapshotObserver *observer=nullptr)
Performs simulations of the game. Pass the available time for computations and the maximum number of ...
Definition: SimulatedGame.cpp:144
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:28
void RemoveUnit(const SimulatedGameThinkingUnit *unit)
Removes a regular unit from the game Might be useful when the game object is reused for different sit...
Definition: SimulatedGame.cpp:242
std::vector< SimulatedGameActionMetadata > GetStartingUnitActionsWithMetadata() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:331
This class should not be visible to developers at all.
Definition: SimulatedGameNode.hh:25
const ISimulatedGameAction * GetStartingUnitBestAction() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:284