Beispiel #1
0
Datei: MCTS.cs Projekt: f15h96/AI
    /*
     * the main MCTS algorithm
     */
    private void MonteCarlowTreeSearch(Node node)
    {
        while (iterations != maxIterations)
        {
            List <GameObject> enemies = new List <GameObject>();
            if (simulationDone)
            {
                SelectNode(node);
                if (node.possibleChildren.Count > 0)
                {
                    PickNode(node);
                    if (CurrNode == node)
                    {
                        MonteCarlowTreeSearch(node);
                    }
                }
                enemies = CreateEnemyList(CurrNode, true);
                gameCopy.Reset();


                gameCopy.startWave(enemies);
            }

            /*
             * while (GameObject.FindGameObjectsWithTag("Enemy") != null)
             * {
             *  simulationDone = false;
             * }
             */

            if (simulationDone)
            {
                iterations++;
                CurrNode.score  = gameCopy.furthest;
                CurrNode.reward = UCB(CurrNode);
                CurrNode.possibleStates(CurrNode, CurrNode.currentCurrency);
                BackPropagate(CurrNode);
            }
        }
        var resultNode = FindNodeWithHighestUCB(CurrNode);

        resultNode.Decisions.Add(resultNode.Decision);
        for (int i = 0; i < resultNode.Decisions.Count; i++)
        {
            switch (resultNode.Decision)
            {
            case "EnemyL":
                Spawn.SpawnL();
                break;

            case "EnemyM":
                Spawn.SpawnM();
                break;

            case "EnemyS":
                Spawn.SpawnS();
                break;
            }
        }
    }