/// <summary> /// Creates a new instance. /// </summary> /// <param name="playout">The strategy used to play out a game in simulation.</param> /// <param name="evaluation">The evaluation strategy for determining the value of samples.</param> /// <param name="gameLogic">The game specific logic required for searching through SabberStoneStates and SabberStoneActions.</param> public SabberStoneSideInformationStrategy(IPlayoutStrategy <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction> playout, IStateEvaluation <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction, TreeSearchNode <SabberStoneState, SabberStoneAction> > evaluation, IGameLogic <List <SabberStoneAction>, SabberStoneState, SabberStoneAction, object, SabberStoneAction, SabberStoneAction> gameLogic) { PlayoutBot = new RandomBot(); Playout = playout; Evaluation = evaluation; GameLogic = gameLogic; }
public void Setup(IGameLogic <object, TicTacToeState, TicTacToeMove, object, TicTacToeMove, TicTacToeMove> gameLogic, IPlayoutStrategy <object, TicTacToeState, TicTacToeMove, object, TicTacToeMove> playoutStrategy, IStateEvaluation <object, TicTacToeState, TicTacToeMove, object, TicTacToeMove, TreeSearchNode <TicTacToeState, TicTacToeMove> > evaluation) { GameLogic = gameLogic; PlayoutStrategy = playoutStrategy; EvaluationStrategy = evaluation; }
/// <summary> /// Creates a new instance of a Linear Side Information search. /// </summary> /// <param name="sideInformationStrategy">The strategy used to create the side information.</param> /// <param name="samplingStrategy">A strategy to sample actions during the Generation process.</param> /// <param name="playout">The strategy used to play out a game in simulation.</param> /// <param name="evaluation">The evaluation strategy for determining the value of samples.</param> /// <param name="gameLogic">The game specific logic required for searching.</param> /// <param name="budgetEstimationStrategy">The strategy used to determine the number of samples to be used in the different phases.</param> public LSI(ISideInformationStrategy <D, P, A, S, A, T> sideInformationStrategy, ILSISamplingStrategy <P, A, T> samplingStrategy, IPlayoutStrategy <D, P, A, S, A> playout, IStateEvaluation <D, P, A, S, A, N> evaluation, IGameLogic <D, P, A, S, A, A> gameLogic, IBudgetEstimationStrategy <D, P, A, S, A> budgetEstimationStrategy) { SideInformationStrategy = sideInformationStrategy; SamplingStrategy = samplingStrategy; Playout = playout; Evaluation = evaluation; GameLogic = gameLogic; BudgetEstimationStrategy = budgetEstimationStrategy; }
/// <summary> /// Constructs a new instance without time or iterative restrictions. /// </summary> /// <param name="selectionStrategy">The selection strategy.</param> /// <param name="expansionStrategy">The expansion strategy.</param> /// <param name="backPropagationStrategy">The back propagation strategy.</param> /// <param name="finalNodeSelectionStrategy">The final node selection strategy.</param> /// <param name="evaluationStrategy">The state evaluation strategy.</param> /// <param name="solutionStrategy">The solution strategy.</param> /// <param name="time">[Optional] The time budget for this search. Default value is <see cref="Constants.NO_LIMIT_ON_THINKING_TIME"/>.</param> /// <param name="iterations">[Optional] The iteration budget for this search. Default value is <see cref="Constants.NO_LIMIT_ON_ITERATIONS"/>.</param> protected TreeSearch(ITreeSelection <D, P, A, S, Sol> selectionStrategy, ITreeExpansion <D, P, A, S, Sol> expansionStrategy, ITreeBackPropagation <D, P, A, S, Sol> backPropagationStrategy, ITreeFinalNodeSelection <D, P, A, S, Sol> finalNodeSelectionStrategy, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluationStrategy, ISolutionStrategy <D, P, A, S, Sol, TreeSearchNode <P, A> > solutionStrategy, long time = Constants.NO_LIMIT_ON_THINKING_TIME, int iterations = Constants.NO_LIMIT_ON_ITERATIONS) { SelectionStrategy = selectionStrategy; ExpansionStrategy = expansionStrategy; BackPropagationStrategy = backPropagationStrategy; FinalNodeSelectionStrategy = finalNodeSelectionStrategy; EvaluationStrategy = evaluationStrategy; SolutionStrategy = solutionStrategy; Time = time; Iterations = iterations; }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="selectionStrategy">The selection strategy.</param> /// <param name="expansionStrategy">The expansion strategy.</param> /// <param name="backPropagationStrategy">The back propagation strategy.</param> /// <param name="finalNodeSelectionStrategy">The final node selection strategy.</param> /// <param name="evaluationStrategy">The state evaluation strategy.</param> /// <param name="solutionStrategy">The solution strategy.</param> /// <param name="playoutStrategy">The playout strategy.</param> /// <param name="time">The amount of time allowed for the search.</param> /// <param name="iterations">The amount of iterations allowed for the search.</param> public FlatMCS(ITreeSelection <D, P, A, S, Sol> selectionStrategy, ITreeExpansion <D, P, A, S, Sol> expansionStrategy, ITreeBackPropagation <D, P, A, S, Sol> backPropagationStrategy, ITreeFinalNodeSelection <D, P, A, S, Sol> finalNodeSelectionStrategy, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluationStrategy, ISolutionStrategy <D, P, A, S, Sol, TreeSearchNode <P, A> > solutionStrategy, IPlayoutStrategy <D, P, A, S, Sol> playoutStrategy, long time, int iterations) : base( selectionStrategy, expansionStrategy, backPropagationStrategy, finalNodeSelectionStrategy, evaluationStrategy, solutionStrategy, time, iterations) { PlayoutStrategy = playoutStrategy; }
/// <summary> /// Propagate an evaluation value of the argument state starting from the argument node back up to the root node. /// </summary> /// <param name="context">The context of the search.</param> /// <param name="evaluation">The strategy used to evaluate the state.</param> /// <param name="node">The node from which the backpropagation starts.</param> /// <param name="state">The state that should be evaluated.</param> public void BackPropagate(SearchContext <D, P, A, S, Sol> context, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluation, TreeSearchNode <P, A> node, P state) { do { // Evaluate state with respect to the node. var value = evaluation.Evaluate(context, node, state); // Visit the node with that evaluation. node.Visit(value); // Keep moving up the tree while there is a valid parent. } while ((node = node.Parent) != null); }
/// <summary> /// Constructs a new instance. /// </summary> /// <param name="selectionStrategy">The selection strategy.</param> /// <param name="expansionStrategy">The expansion strategy.</param> /// <param name="backPropagationStrategy">The back propagation strategy.</param> /// <param name="finalNodeSelectionStrategy">The final node selection strategy.</param> /// <param name="evaluationStrategy">The state evaluation strategy.</param> /// <param name="explorationStrategy">The exploration strategy.</param> /// <param name="solutionStrategy">The solution strategy.</param> /// <param name="samplingStrategy">The sampling strategy.</param> /// <param name="playoutStrategy">The playout strategy.</param> /// <param name="time">The amount of time allowed for the search.</param> /// <param name="iterations">The amount of iterations allowed for the search.</param> /// <param name="globalPolicy">The global policy.</param> public NMCTS(ITreeSelection <D, P, A, S, Sol> selectionStrategy, ITreeExpansion <D, P, A, S, Sol> expansionStrategy, ITreeBackPropagation <D, P, A, S, Sol> backPropagationStrategy, ITreeFinalNodeSelection <D, P, A, S, Sol> finalNodeSelectionStrategy, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluationStrategy, IExplorationStrategy <D, P, A, S, Sol> explorationStrategy, ISolutionStrategy <D, P, A, S, Sol, TreeSearchNode <P, A> > solutionStrategy, ISamplingStrategy <P, A> samplingStrategy, IPlayoutStrategy <D, P, A, S, Sol> playoutStrategy, long time, int iterations, double globalPolicy) : base(selectionStrategy, expansionStrategy, backPropagationStrategy, finalNodeSelectionStrategy, evaluationStrategy, solutionStrategy, time, iterations) { ExplorationStrategy = explorationStrategy; SamplingStrategy = samplingStrategy; PlayoutStrategy = playoutStrategy; PolicyGlobal = globalPolicy; }
/// <summary> /// Propagate an evaluation value of the argument state starting from the argument node back up to the root node. /// </summary> /// <param name="context">The context of the search.</param> /// <param name="evaluation">The strategy used to evaluate the state.</param> /// <param name="node">The node from which the backpropagation starts.</param> /// <param name="state">The state that should be evaluated.</param> public void BackPropagate(SearchContext <D, P, A, S, Sol> context, IStateEvaluation <D, P, A, S, Sol, TreeSearchNode <P, A> > evaluation, TreeSearchNode <P, A> node, P state) { // Evaluate the state with respect to the argument node. var value = evaluation.Evaluate(context, node, state); // The root player is the current player in the search's source state. var rootPlayer = context.Source.CurrentPlayer(); do { // Check whether or not this node is a root player's node. var targetPlayer = node.IsRoot() || rootPlayer == node.Payload.Player(); // Visits the node with a coloured evaluation value. node.Visit(targetPlayer ? value : -value); // Keep moving up the tree while there is a valid parent. } while ((node = node.Parent) != null); }