Exemplo n.º 1
0
    private void SelectionAndExpantion()
    {
        int option = ChooseRandomAction();

        if (!currentNode.checkChildren(option))
        {
            MonteCarloTree.Node nodeToAdd = new MonteCarloTree.Node();
            nodeToAdd.NodeOption = option;
            currentNode.AddChild(nodeToAdd);
        }

        float highestUCB = -1.0f;

        MonteCarloTree.Node testNode = currentNode;
        for (int i = 0; i < currentNode.GetNumberOfChildren(); i++)
        {
            float UCB = UpperConfidenceBound(currentNode.GetChild(i));
            if (highestUCB < UCB)
            {
                testNode   = currentNode.GetChild(i);
                highestUCB = UCB;
            }
        }
        currentNode = testNode;
        nodeOptions = (NodeOptions)currentNode.NodeOption;
    }
        public void Traverse(Node currentNode)
        {
            int numberOfChildNodes = currentNode.GetNumberOfChildren();

            if (numberOfChildNodes > 0)
            {
                for (int i = 0; i < numberOfChildNodes; i++)
                {
                    Node childToTraverse = currentNode.GetChild(i);
                    Traverse(childToTraverse);
                }
            }
        }