Esempio n. 1
0
    /* Check if this generation has crashed yet.
     * If it has, inform the genepool so that it can perform the pre-defined genetic operators
     * and spawn the next generation. */
    void CheckOnGeneration()
    {
        // If this whole generation has crashed
        if (genePool.PoolStillAlive() == false)
        {
            genePool.pool.Sort();

            // Sort the population based on fitness and report the best one
            Structure bestGenome = genePool.GetBestGenome();
            dashboard.UpdateMaxFitness(bestGenome.GetFitness());

            // Destory all old cars
            GameObject[] allPlayers = GameObject.FindGameObjectsWithTag("Player");
            for (int i = 0; i < allPlayers.Length; i++)
            {
                Destroy(allPlayers[i]);
            }

            generationNumber++;
            dashboard.UpdateGeneration(generationNumber);
            genePool.NextGeneration();
        }
    }