|
Grail (C++)
1.1.1
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
1 #ifndef GRAIL_SIMULATED_GAME_H
2 #define GRAIL_SIMULATED_GAME_H
4 #include "ISimulatedGameUnit.hh"
5 #include "SimulatedGameActionMetadata.hh"
6 #include "SimulatedGameHelper.h"
7 #include "SimulatedGameNode.h"
8 #include "SimulatedGameSnapshotObserver.h"
12 #include <unordered_map>
19 class SimulatedGameThinkingUnit;
20 class SimulatedGameStochasticUnit;
21 class ISimulatedGameAction;
22 class SimulatedGameNode;
42 double maxScore = 1.0,
43 double explorationBoost = 1.0,
44 size_t freezeVisitsTreshold = std::numeric_limits<size_t>::max(),
45 RandomGenerator::result_type seed = std::random_device{}());
58 void AddUnits(std::vector<std::shared_ptr<SimulatedGameThinkingUnit>> units);
93 std::vector<std::pair<const ISimulatedGameUnit*, const ISimulatedGameAction*>>
GetExpectedPlayout()
const;
105 std::unordered_map<const ISimulatedGameUnit*, std::vector<const ISimulatedGameAction*>>
GetExpectedPlans();
111 std::unordered_map<const ISimulatedGameUnit*, std::vector<SimulatedGameActionMetadata>>
122 virtual size_t Run(
size_t milisecondsTotal,
123 size_t maxIterationCount,
127 std::unordered_map<
const ISimulatedGameUnit*, std::vector<const ISimulatedGameAction*>>& plan)
const;
128 void DebugPrintPlanWithMetadata(
129 std::unordered_map<
const ISimulatedGameUnit*, std::vector<SimulatedGameActionMetadata>>& plan)
const;
130 void DebugPrintFullPlayout(
131 std::vector<std::pair<const ISimulatedGameUnit*, const ISimulatedGameAction*>>& playout)
const;
150 std::vector<std::shared_ptr<SimulatedGameThinkingUnit>> thinkingUnits{};
151 std::vector<std::shared_ptr<SimulatedGameStochasticUnit>> stochasticUnits{};
153 RandomGenerator rand_gen{};
154 std::unique_ptr<SimulatedGameNode> rootNode{};
161 #endif //GRAIL_SIMULATED_GAME_H
std::vector< SimulatedGameActionMetadata > GetStartingUnitActionsWithMetadata() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:329
Base class for all actions in SimulatedGame. Derive from it for your actions.
Definition: ISimulatedGameAction.hh:39
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:240
This class should not be visible to developers at all.
Definition: SimulatedGameNode.h:23
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:142
void ClearStatistics()
This method invalidates the tree built for the game. If any offline learners were attached,...
Definition: SimulatedGame.cpp:94
const ISimulatedGameAction * GetStartingUnitBestAction() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:282
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm....
Definition: SimulatedGame.hh:28
void SetStartingUnit(SimulatedGameThinkingUnit &unit)
Gets or sets the unit that acts first in the starting state of the game.
Definition: SimulatedGame.cpp:89
Definition: SimulatedGameHelper.h:16
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:308
void AddUnits(std::vector< std::shared_ptr< SimulatedGameThinkingUnit >> units)
Adds new regular units to the game.
Definition: SimulatedGame.cpp:273
Definition: SimulatedGameSnapshotObserver.h:21
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:297
const SimulatedGameActionMetadata GetStartingUnitBestActionMetadata() const
Call this method after certain number of iterations performed (by calling Run() first).
Definition: SimulatedGame.cpp:291
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:319
A base class of a unit related to a rational/intelligent player. MCTS chooses actions for this kind o...
Definition: SimulatedGameThinkingUnit.hh:21
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:193
A base class of a unit in SimulatedGame that peforms actions according to some probability distributi...
Definition: SimulatedGameStochasticUnit.hh:21
SimulatedGameThinkingUnit & AddUnit(std::shared_ptr< SimulatedGameThinkingUnit > unit)
Adds a new regular unit to the game.
Definition: SimulatedGame.cpp:223
Base class of a unit in the SimulatedGame framework. A unit represents part of the game-state and pef...
Definition: ISimulatedGameUnit.hh:26