示例#1
0
        internal static Node<Data> simulateGame(int searchWidth, int searchDepth, int copnumber, Node<Data> node, Board board)
        {
            if (searchDepth != 0)
            {
                Data nodeInfo = node.GetData();
                List<int> neighborList = new List<int>(board.findNeighbors(nodeInfo.RobberPos));
                List<int> path = new List<int>();
                int robberNodePosition;
                for (int i = 0; i < searchWidth; i++)
                {
                    node.AddChild(FindChildOnBoard(neighborList, nodeInfo, copnumber, out robberNodePosition, board));
                    if (neighborList.Contains(robberNodePosition))
                        neighborList.Remove(robberNodePosition);
                }
                //obliczanie prawdopodobieństw do ruchu na zaraz
                int sum = 0, iter = 0, maxNode = 0;
                double maxProbNode = 0;
                foreach (Node<Data> child in node.GetChildren())
                {
                    sum += child.GetData().RobberCopDistance;
                }
                foreach (Node<Data> child in node.GetChildren())
                {
                    child.GetData().Probability = (double)child.GetData().RobberCopDistance / sum;
                    if (child.GetData().Probability > maxProbNode)
                    {
                        maxProbNode = child.GetData().Probability;
                        maxNode = iter;
                    }
                    iter++;
                }
                simulateGame(searchWidth, searchDepth - 1, copnumber, node.GetChild(maxNode), board);
            }

            return node;
        }
示例#2
0
 internal static Node<Data> PropagateChildrenProbability(Node<Data> nodeTMP)
 {
     while (true)
     {
         if (nodeTMP.areAllChildrenLeaf() || nodeTMP.GetData().Visited == 1)
         {
             nodeTMP.GetData().Visited = 1;
             break;
         }
         foreach (Node<Data> child in nodeTMP.GetChildren())
         {
             if (child.IsLeaf())
             {
                 if (child.GetData().Probability > child.GetParent().GetData().Probability)
                 {
                     child.GetParent().GetData().Probability = child.GetData().Probability;
                 }
                 child.GetData().Visited = 1;
             }
             else
             {
                 PropagateChildrenProbability(child);
                 child.GetData().Visited = 1;
             }
         }
     }
     return nodeTMP;
 }