Example #1
0
        public Dna Crossover(Dna otherParent)
        {
            var childGenes = new Vector2[Genes.Length];

            //for (int i = 0; i < Genes.Length; i++)
            //{
            //    childGenes[i] = Random.Range(0.0f, 1.0f) < 0.5f ? Genes[i] : otherParent.Genes[i];
            //}

            //return new Dna(_lifetime, childGenes);

            int midPoint = Random.Range(0, Genes.Length);

            for (int i = 0; i < Genes.Length; i++)
            {
                if (i < midPoint)
                {
                    childGenes[i] = Genes[i];
                }
                else
                {
                    childGenes[i] = otherParent.Genes[i];
                }
            }

            return(new Dna(_lifetime, childGenes));
        }
Example #2
0
 public void ConstructorWithDna(Dna dna)
 {
     _geneCounter    = 0;
     _completionTime = 0;
     _hitTarget      = false;
     _hitObstacle    = false;
     Dna             = dna;
 }
Example #3
0
 public void ConstructorWithoutDna(int lifetime, float maxForce)
 {
     _lifeTime = lifetime;
     _maxForce = maxForce;
     Dna       = new Dna(_lifeTime, _maxForce);
 }