private Node TreePolicy(Node node) { var state = node.State; while (state?.State != State.COMPLETE && node.TurnDepth < TurnDepth) { if (state == null) { return(node); } if (FullyExpanded(node)) { var selectionStrategy = SelectionStrategies.GetSelectionStrategy(Selection); var stateRateStrategy = StateRateStrategies.GetStateRateStrategy(StateRate); node = ChildSelection.SelectBestChild(state, node, EXPLORATION_CONSTANT, player, selectionStrategy, stateRateStrategy); state = state.Simulate(new List <PlayerTask> { node.Action })[node.Action]; } else { return(Expand(node, state)); } } return(node); }
public PlayerTask Search() { List <PlayerTask> options = player.Options(); if (options.Count == 1 && options[0].PlayerTaskType == PlayerTaskType.END_TURN) { return(options.First()); } StopWatch.Start(); var selectionStrategy = SelectionStrategies.GetSelectionStrategy(Selection); var stateRateStrategy = StateRateStrategies.GetStateRateStrategy(StateRate); while (StopWatch.ElapsedMilliseconds < COMPUTATIONAL_BUDGET) { POGame state = InitialState.getCopy(); Node lastNode = TreePolicy(Root); float delta = DefaultPolicyHeuristic(lastNode); Backup(lastNode, delta); } StopWatch.Stop(); return(ChildSelection.SelectBestChild(InitialState, Root, EXPLORATION_CONSTANT, player, selectionStrategy, stateRateStrategy).Action); }