Grail (C++)
1.4.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
|
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm. The class supports definition of a game, running simulations and obtaining results. More...
#include <SimulatedGame.hh>
Public Member Functions | |
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. More... | |
SimulatedGameThinkingUnit & | AddUnit (std::shared_ptr< SimulatedGameThinkingUnit > unit) |
Adds a new regular unit to the game. More... | |
void | AddUnits (std::vector< std::shared_ptr< SimulatedGameThinkingUnit >> units) |
Adds new regular units to the game. | |
SimulatedGameStochasticUnit & | AddUnit (std::shared_ptr< SimulatedGameStochasticUnit > unit) |
Adds a new stochastic (performing random actions) unit to the game. More... | |
void | RemoveUnit (const SimulatedGameThinkingUnit *unit) |
Removes a regular unit from the game Might be useful when the game object is reused for different situations. | |
void | RemoveUnit (const SimulatedGameStochasticUnit *unit) |
Removes a stochastic (performing random actions) unit to the game. Might be useful when the game object is reused for different situations. | |
const ISimulatedGameAction * | GetStartingUnitBestAction () const |
Call this method after certain number of iterations performed (by calling Run() first). | |
const SimulatedGameActionMetadata | GetStartingUnitBestActionMetadata () const |
Call this method after certain number of iterations performed (by calling Run() first). More... | |
std::vector< std::pair< const ISimulatedGameUnit *, const ISimulatedGameAction * > > | GetExpectedPlayout () const |
Call this method after certain number of iterations performed (by calling Run() first). More... | |
std::vector< SimulatedGameActionMetadata > | GetStartingUnitActionsWithMetadata () const |
Call this method after certain number of iterations performed (by calling Run() first). More... | |
std::unordered_map< const ISimulatedGameUnit *, std::vector< const ISimulatedGameAction * > > | GetExpectedPlans () |
Call this method after certain number of iterations performed (by calling Run() first). More... | |
std::unordered_map< const ISimulatedGameUnit *, std::vector< SimulatedGameActionMetadata > > | GetExpectedPlansWithMetadata () |
Call this method after certain number of iterations performed (by calling Run() first). More... | |
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 iterations. Both parameters have relatively high default values. The method returns when at least one termination condition occurs. More... | |
void | DebugPrintPlan (std::unordered_map< const ISimulatedGameUnit *, std::vector< const ISimulatedGameAction * >> &plan) const |
void | DebugPrintPlanWithMetadata (std::unordered_map< const ISimulatedGameUnit *, std::vector< SimulatedGameActionMetadata >> &plan) const |
void | DebugPrintFullPlayout (std::vector< std::pair< const ISimulatedGameUnit *, const ISimulatedGameAction * >> &playout) const |
void | SetStartingUnit (SimulatedGameThinkingUnit &unit) |
Gets or sets the unit that acts first in the starting state of the game. | |
void | ClearStatistics () |
This method invalidates the tree built for the game. If any offline learners were attached, their gathered data is cleared too. This method effectively reverts all changes done by the Run() method. | |
The main interface class for the SimulatedGame reasoner based on the MCTS algorithm. The class supports definition of a game, running simulations and obtaining results.
grail::simgames::SimulatedGame::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.
teamCount | - This is the number of intelligent players in the game. Each team shares the score that is given when the game ends. |
maxGameScore | - The maximum score that can be awarded to a team when the game ends. This value does not need to be given precisely or even correctly. However, the closer to the correct maximum value, the better for the algorithm's efficiency. |
explorationBoost | - A modifier that affects how much exploration of state-space is boosted compared to the default value of 1. Values lower than 1.0 will reduce the exploration. Values lower than 0.1 will be clamped to 0.1. |
freezeVisitsTreshold | - When a certain state is visited at least this number of times, then the best action so far will be fixed as the final chosen action (no more exploration here). |
seed | - Initialization seed to the random number generator. |
SimulatedGameStochasticUnit & grail::simgames::SimulatedGame::AddUnit | ( | std::shared_ptr< SimulatedGameStochasticUnit > | unit | ) |
Adds a new stochastic (performing random actions) unit to the game.
SimulatedGameThinkingUnit & grail::simgames::SimulatedGame::AddUnit | ( | std::shared_ptr< SimulatedGameThinkingUnit > | unit | ) |
Adds a new regular unit to the game.
std::unordered_map< const ISimulatedGameUnit *, std::vector< const ISimulatedGameAction * > > grail::simgames::SimulatedGame::GetExpectedPlans | ( | ) |
Call this method after certain number of iterations performed (by calling Run() first).
std::unordered_map< const ISimulatedGameUnit *, std::vector< SimulatedGameActionMetadata > > grail::simgames::SimulatedGame::GetExpectedPlansWithMetadata | ( | ) |
Call this method after certain number of iterations performed (by calling Run() first).
std::vector< std::pair< const ISimulatedGameUnit *, const ISimulatedGameAction * > > grail::simgames::SimulatedGame::GetExpectedPlayout | ( | ) | const |
Call this method after certain number of iterations performed (by calling Run() first).
std::vector< SimulatedGameActionMetadata > grail::simgames::SimulatedGame::GetStartingUnitActionsWithMetadata | ( | ) | const |
Call this method after certain number of iterations performed (by calling Run() first).
const SimulatedGameActionMetadata grail::simgames::SimulatedGame::GetStartingUnitBestActionMetadata | ( | ) | const |
Call this method after certain number of iterations performed (by calling Run() first).
|
virtual |
Performs simulations of the game. Pass the available time for computations and the maximum number of iterations. Both parameters have relatively high default values. The method returns when at least one termination condition occurs.
milisecondsTotal | - The time allowed for iterations in miliseconds. |
maxIterationCount | - The number of iterations to perform. |
observer | - SimulatedGameSnapshotObserver object that provides additional feedback from simulations. Used for GUI tools debugging; warning: comes with computational overhead. Pass null for high-performance execution. |