Grail (C#)  1.2.0
A multi-platform, modular, universal engine for embedding advanced AI in games.
Grail.SimulatedGames.SimulatedGame Class Reference

The main interface class for the SimulatedGame model based on the MCTS algorithm. The class supports definition of a game, running simulations and obtaining results. More...

Public Member Functions

 SimulatedGame (int teamCount=2, double maxGameScore=1.0, double explorationBoost=1.0, uint freezeVisitsTreshold=uint.MaxValue)
 Constructs a new SimulatedGame object. This object can be reused. More...
 
int Run (uint milisecondsTotal=30000, uint maxIterationCount=100000, SimulatedGameSnapshotObserver snapshotObserver=null)
 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 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. More...
 
SimulatedGameThinkingUnit AddUnit (SimulatedGameThinkingUnit unit)
 Adds a new regular unit to the game. More...
 
SimulatedGameStochasticUnit AddUnit (SimulatedGameStochasticUnit unit)
 Adds a new stochastic (performing random actions) unit to the game. More...
 
void RemoveUnit (SimulatedGameThinkingUnit unit)
 Removes a regular unit from the game Might be useful when the game object is reused for different situations. More...
 
void RemoveUnit (SimulatedGameStochasticUnit unit)
 Removes a stochastic (performing random actions) unit to the game. Might be useful when the game object is reused for different situations. More...
 
Dictionary< ISimulatedGameUnit, List< ISimulatedGameAction > > GetExpectedPlans ()
 Call this method after certain number of iterations performed (by calling Run() first). More...
 
Dictionary< ISimulatedGameUnit, List< SimulatedGameActionMetadata > > GetExpectedPlansWithMetadata ()
 Call this method after certain number of iterations performed (by calling Run() first). More...
 
Dictionary< ISimulatedGameAction, SimulatedGameActionMetadataGetStartingUnitActionsMetadata ()
 Call this method after certain number of iterations performed (by calling Run() first). More...
 
ISimulatedGameAction GetStartingUnitBestAction ()
 Call this method after certain number of iterations performed (by calling Run() first). More...
 
List< Tuple< ISimulatedGameUnit, ISimulatedGameAction > > GetExpectedPlayout ()
 Call this method after certain number of iterations performed (by calling Run() first). More...
 

Properties

SimulatedGameThinkingUnit StartingUnit [get, set]
 Gets or sets the unit that acts first in the starting state of the game. More...
 

Detailed Description

The main interface class for the SimulatedGame model based on the MCTS algorithm. The class supports definition of a game, running simulations and obtaining results.

Constructor & Destructor Documentation

◆ SimulatedGame()

Grail.SimulatedGames.SimulatedGame.SimulatedGame ( int  teamCount = 2,
double  maxGameScore = 1.0,
double  explorationBoost = 1.0,
uint  freezeVisitsTreshold = uint.MaxValue 
)
inline

Constructs a new SimulatedGame object. This object can be reused.

Parameters
teamCountThis is the number of intelligent players in the game. Each team shares the score that is given when the game ends.
maxGameScoreThe 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.
explorationBoostA modifier that affects how much exploration of state-space is boosted compared to the default value of 1. e Values lower than 1.0 will reduce the exploration. Values lower than 0.1 will be clamped to 0.1.
freezeVisitsTresholdWhen 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).

Member Function Documentation

◆ AddUnit() [1/2]

SimulatedGameThinkingUnit Grail.SimulatedGames.SimulatedGame.AddUnit ( SimulatedGameThinkingUnit  unit)
inline

Adds a new regular unit to the game.

Parameters
unit
Returns
Returns the added unit.

◆ AddUnit() [2/2]

SimulatedGameStochasticUnit Grail.SimulatedGames.SimulatedGame.AddUnit ( SimulatedGameStochasticUnit  unit)
inline

Adds a new stochastic (performing random actions) unit to the game.

///

Parameters
unit
Returns
Returns the added unit.

◆ ClearStatistics()

void Grail.SimulatedGames.SimulatedGame.ClearStatistics ( )
inline

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.

◆ GetExpectedPlans()

Dictionary<ISimulatedGameUnit, List<ISimulatedGameAction> > Grail.SimulatedGames.SimulatedGame.GetExpectedPlans ( )
inline

Call this method after certain number of iterations performed (by calling Run() first).

Returns
List of actions per unit that have are the most promising and probable.

◆ GetExpectedPlansWithMetadata()

Dictionary<ISimulatedGameUnit, List<SimulatedGameActionMetadata> > Grail.SimulatedGames.SimulatedGame.GetExpectedPlansWithMetadata ( )
inline

Call this method after certain number of iterations performed (by calling Run() first).

Returns
List of actions per unit with additional statistics that have are the most promising and probable.

◆ GetExpectedPlayout()

List<Tuple<ISimulatedGameUnit, ISimulatedGameAction> > Grail.SimulatedGames.SimulatedGame.GetExpectedPlayout ( )
inline

Call this method after certain number of iterations performed (by calling Run() first).

Returns
List of ordered pairs (unit, action) that have are the most promising and probable.

◆ GetStartingUnitActionsMetadata()

Dictionary<ISimulatedGameAction, SimulatedGameActionMetadata> Grail.SimulatedGames.SimulatedGame.GetStartingUnitActionsMetadata ( )
inline

Call this method after certain number of iterations performed (by calling Run() first).

Returns
Currently available actions of the starting unit with additional statistics

◆ GetStartingUnitBestAction()

ISimulatedGameAction Grail.SimulatedGames.SimulatedGame.GetStartingUnitBestAction ( )
inline

Call this method after certain number of iterations performed (by calling Run() first).

◆ RemoveUnit() [1/2]

void Grail.SimulatedGames.SimulatedGame.RemoveUnit ( SimulatedGameThinkingUnit  unit)
inline

Removes a regular unit from the game Might be useful when the game object is reused for different situations.

◆ RemoveUnit() [2/2]

void Grail.SimulatedGames.SimulatedGame.RemoveUnit ( SimulatedGameStochasticUnit  unit)
inline

Removes a stochastic (performing random actions) unit to the game. Might be useful when the game object is reused for different situations.

◆ Run()

int Grail.SimulatedGames.SimulatedGame.Run ( uint  milisecondsTotal = 30000,
uint  maxIterationCount = 100000,
SimulatedGameSnapshotObserver  snapshotObserver = null 
)
inline

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.

Parameters
milisecondsTotalThe time allowed for iterations in miliseconds.
maxIterationCountThe number of iterations to perform.
snapshotObserverISimulatedGameObserver object that provides additional feedback from simulations. Used for GUI tools debugging; warning: comes with computational overhead. Pass null for high-performance execution.
Returns
Returns the number of iterations performed.

Property Documentation

◆ StartingUnit

SimulatedGameThinkingUnit Grail.SimulatedGames.SimulatedGame.StartingUnit
getset

Gets or sets the unit that acts first in the starting state of the game.


The documentation for this class was generated from the following file: