public void CreateGeneration()
    {
        if (gen > generations)
        {
            return;
        }

        population.Sort();
        List <EvolEnemy> templateList = new List <EvolEnemy>();
        int i, x;

        for (i = mu; i < population.Count; i++)
        {
            EvolEnemy template = population[i].template;
            templateList.Add(template);
            population[i].Revive();
        }

        bool isRandom = templateList.Count != mu;

        for (i = 0; i < mu; i++)
        {
            x = i;
            if (isRandom)
            {
                x = Random.Range(0, templateList.Count - 1);
            }
            population[i].template = templateList[x];
            population[i].Revive();
        }

        gen++;
        numAlive = population.Count;
    }
示例#2
0
    public void CreateGeneration()
    {
        //check if the number of generations created is greater than allowed
        if (gen > generations)
        {
            return;
        }
        //sort the individuals in ascending order, and create a list of surviving individuals
        population.Sort();
        List <EvolEnemy> templateList = new List <EvolEnemy>();
        int i, x;

        for (i = mu; i < population.Count; i++)
        {
            EvolEnemy template = population[i].template;
            templateList.Add(template);
            population[i].Revive();
        }

        //create new individuals from the surviving types
        bool isRandom = templateList.Count != mu;

        for (i = 0; i < mu; i++)
        {
            x = i;
            if (isRandom)
            {
                x = Random.Range(0, templateList.Count - 1);
            }

            population[i].template = templateList[x];
            population[i].Revive();
        }

        //increase the number of generations, and reset the number of individuals alive
        gen++;
        numAlive = population.Count;
    }
 public void Init(EvolEnemy template, Vector2 bounds)
 {
     this.template = template;
     this.bounds   = bounds;
     Revive();
 }