コード例 #1
0
    public KeyValuePair <Move, int> RunPNS(NodeTree root, int depht, bool isInitial, bool isMaximizing, Stopwatch timer)
    {
        searchCount    = 0;
        root.nodeScore = root.Evaluation();
        root.setPNS();
        //ExpandNode (root/*, depht*/);
        SetProofAndDisproof(root);
        NodeTree currentNode = root;

        //int depthTmp = depth;
        while (root.proof != 0 && root.disproof != 0 && timer.ElapsedMilliseconds < 2500 * depth)
        {
            NodeTree mostProving = SelectMostProvingNode(currentNode, depht);
            ExpandNode(mostProving, depth);
            //Console.WriteLine ("expanded");
            //searchCount += mostProving.children.Count;
            currentNode = UpdateAncestors(root, currentNode);
            //Console.WriteLine ("Ancestor update");
        }
        NodeTree    selectedChild    = null;
        int         mostProvingValue = int.MaxValue; //You want the lowest proof number
        List <Move> legalMoves       = root.board.getPlayerMoves(player);

        Console.WriteLine("nb de coup pour root : " + legalMoves.Count + "\nnb root children : " + root.children.Count);
        SetProofAndDisproof(root);
        for (int i = 0; i < root.children.Count; i++)
        {
            if (root.children[i].pns == PNS.PROVEN)
            {
                selectedChild = root.children[i];
                Console.WriteLine("THIS should be winning move");
                break;
            }
            else
            {
                if (mostProvingValue > root.children[i].proof)
                {
                    //Console.Write ("new best proving assignation");
                    mostProvingValue = root.children[i].proof;
                    selectedChild    = root.children[i];
                }
            }
        }
        Console.WriteLine("score : " + mostProvingValue);
        //root.PrintTree ("", true);
        return(new KeyValuePair <Move, int> (selectedChild.move, selectedChild.nodeScore));
    }
コード例 #2
0
 public static void ExpandNode(NodeTree current, int depth)
 {
     if (depth == 0)
     {
         current.Evaluation();
         SetProofAndDisproof(current);
         SetPNSbyScore(current);
         return;
     }
     if (!current.isExpanded)
     {
         current.initChildren();
     }
     foreach (NodeTree child in current.children)
     {
         searchCount++;
         child.nodeScore = child.Evaluation();
         SetProofAndDisproof(child);
         //SetPNSbyScore (child);
         if (child.isMaximizing)               //OR Node
         {
             if (child.proof == 0)
             {
                 break;
             }
         }
         else                 //AND Node
         {
             if (child.disproof == 0)
             {
                 break;
             }
         }
     }
     current.isExpanded = true;
 }