Esempio n. 1
0
 public void Backup(int val)
 {
     score += val;
     timesVisited++;
     if (parent != null)
     {
         parent.Backup(val);
     }
 }
Esempio n. 2
0
    public List <Point> ComputerMoveMTCS()
    {
        //Debug.Log ("computer move");

        List <Point> computerMove = new List <Point> ();
        Point        bestMove     = new Point();


        MonteCarloNode rootNode = new MonteCarloNode(manager.board.state, this);

        for (int i = 0; i < numExpansions; i++)
        {
            MonteCarloNode n = TreePolicy(rootNode);
            n.Backup(Simulate(n));
        }
        //Debug.Log ("finished simulating");
        MonteCarloNode maxNode = null;
        //Debug.Log ("maxnode set");
        double maxVal = double.NegativeInfinity;

        foreach (MonteCarloNode node in rootNode.children)
        {
            if (node.timesVisited == 0)
            {
                continue;
            }
            if ((double)node.score / (double)node.timesVisited > maxVal)
            {
                maxNode = new MonteCarloNode(node);
                maxVal  = (double)node.score / (double)node.timesVisited;
            }
        }

        bestMove = maxNode.point;

        board.state.availableMoves.TryGetValue(bestMove, out computerMove);
        // Have to add the move itself to the list of Points
        computerMove.Insert(0, bestMove);

        return(computerMove);
    }