Beispiel #1
0
    public void AllAgentsKilledCallback(List <AgentObject> agents, List <Species> species, int generation)
    {
        //Destry all player
        foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("Player"))
        {
            Destroy(gameObject);
        }

        GenerationEvaluator eval      = new GenerationEvaluator(agents, species, generation);
        AgentObject         bestAgent = eval.BestAgent;

        Debug.Log("All agents dead. Best fitness: " + bestAgent.GetFitness() + ", Average: " + eval.AverageFitness);

        //GUI Values
        _bestFitnessLastGeneration    = bestAgent.GetFitness();
        _averageFitnessLastGeneration = eval.AverageFitness;

        if (_bestTotalFitness < _bestFitnessLastGeneration)
        {
            _bestTotalFitness = _bestFitnessLastGeneration;
        }
        if (_bestAverageFitness < _averageFitnessLastGeneration)
        {
            _bestAverageFitness = _averageFitnessLastGeneration;
        }

        //Start next generation if the evaluation is running
        if (_evaluationRunning)
        {
            _manager.GenerateNextGeneration();
        }
    }
        public void AllAgentsKilledCallback(List <AgentObject> agents, List <Species> species, int generation)
        {
            //Destry all player
            foreach (GameObject gameObject in GameObject.FindGameObjectsWithTag("Player"))
            {
                Destroy(gameObject);
            }

            GenerationEvaluator eval      = new GenerationEvaluator(agents, species, generation);
            AgentObject         bestAgent = eval.BestAgent;

            Debug.Log("All agents dead. Best fitness: " + bestAgent.GetFitness() + ", Average: " + eval.AverageFitness);

            //Fill the screen
            FillXorScreen(bestAgent.Genome, _screen, _screenObjPrefab);

            SetDisplay(bestAgent.Genome);

            if (CanAgentSolveXOR(bestAgent) || eval.Generation > 500)
            {
                foreach (NodeGene node in bestAgent.Genome.Nodes.Values)
                {
                    Debug.Log("Node: " + node.ID + ", Type: " + node.Type);
                }

                foreach (ConnectionGene connection in bestAgent.Genome.Connections.Values)
                {
                    if (connection.Expressed)
                    {
                        Debug.Log("Connection: In: " + connection.InNode + " Out: " + connection.OutNode + ", Weight: " + connection.Weight + ", InnovationNumber: " + connection.InnovationNumber);
                    }
                }

                result.Add(eval.Generation);

                if (result.Count < amountRuns)
                {
                    _manager.CreateInitialPopulation(startingGenome, new GeneCounter(6), new GeneCounter(9), 400);
                }
                else
                {
                    Debug.Log("FINIIIISHED");
                }
            }
            else
            {
                _manager.GenerateNextGeneration();
            }
        }