Beispiel #1
0
        public UCTNode MonteCarloSearch(UCTNode startNode, List <PlayerTaskType> availableOptionTypes, int step, int depth)
        {
            //GetEndTurnOption(currentNode.currentPOGame) == null
            UCTNode           currentNode = startNode;
            List <PlayerTask> optionsList = AvailableOptions(currentNode, availableOptionTypes);
            bool isStop = false;

            while (!isStop &&
                   step < depth &&
                   optionsList.Count() > 0 &&
                   !currentNode.IsGameOver() ||
                   GetEndTurnOption(currentNode) == null
                   )
            {
                int        rndOptionNo = rnd.Next(optionsList.Count());
                PlayerTask rndOption   = optionsList[rndOptionNo];
                UCTNode    tmpNode     = currentNode.GetChild(rndOptionNo);

                //  if not existed
                if (tmpNode == null)
                {
                    // simulate the option
                    POGame.POGame simulatedPOGame = SimulateOption(currentNode.currentPOGame, rndOption);
                    // some time simulate option returned POGame is null
                    if (simulatedPOGame == null)
                    {
                        isStop = true;
                        Console.WriteLine(currentNode.FullPathPrint());
                        Console.WriteLine(currentNode.FullPrint());
                    }

                    currentNode = currentNode.AddChild(currentNode, rndOption, rndOptionNo, simulatedPOGame);
                }
                //if j child is existed
                else
                {
                    currentNode = tmpNode;
                }
                step++;

                // random select a option
                optionsList = AvailableOptions(currentNode, availableOptionTypes);
            }
            return(currentNode);
        }