Пример #1
0
        /// <summary>
        /// Returns the set of legal actions in the given state with their corresponding
        /// expected values.
        /// </summary>
        /// <param name="state">the game state</param>
        /// <param name="searchLimit">a search limit for the algorithm</param>
        public IEnumerable <ActionValue> GetPolicies(GameState state, ISearchLimit searchLimit)
        {
            TreeRoot = new DecisionNode(state);
            while (!searchLimit.Done())
            {
                SampleSearchTree(TreeRoot);
            }

            var results = new List <ActionValue>(TreeRoot.Children.Select(pair => new ActionValue()
            {
                Action = pair.Key,
                Value  = pair.Value.VisitCount > 0 ? pair.Value.AverageValue : 0
            }));

            RandomProvider.Shuffle(results);             // break ties randomly

            return(results);
        }
Пример #2
0
 /// <summary>
 /// Returns the best action to take in the given state using the given
 /// search limit.
 /// </summary>
 /// <param name="state">the game state</param>
 /// <param name="searchLimit">the search limit</param>
 /// <returns></returns>
 public Action GetPolicy(GameState state, ISearchLimit searchLimit)
 {
     return(GetPolicies(state, searchLimit).Best());
 }