Пример #1
0
 // Update is called once per frame
 void Update()
 {
     if (!gameOver)
     {
         distance += Time.deltaTime;
         for (int i = 0; i < numOfUnitsInGeneration; i++)
         {
             if (birds[i].isDead == false)
             {
                 float[] inputs = new float[2];                     // prepare the genetic activate function inputs
                 // Will set inputs to the distance in x and height difference in y to the nearest column
                 columnSpawn.GetNearestColumn(birds[i].transform, out inputs[0], out inputs[1]);
                 float[] result = genetic.ActivateBrain(i, inputs);
                 if (result[0] > 0.5f)                       // treat results greater than 0.5 as true
                 {
                     birds[i].flapOnNextFrame = true;
                 }
             }
         }
     }
     else
     {
         // Game is over, either all the population has died or game ended with max score reached
         // In any case, evolve the population and run the next generation
         genetic.EvolvePopulation();
         generationNum      += 1;
         generationText.text = "Generation: " + generationNum;
         //generationText.text = "Generation: " + generationNum.ToString();
         Restart();
     }
 }