Ejemplo n.º 1
0
 private void Mutate(ref Dna genesMutate)
 {
     for (int i = 0; i < genesMutate.genes.Length; i++)
     {
         int n = RandomGen.rnd.Next(0, 1000);
         if (n < Settings.mutationRate)
         {
             genesMutate.genes[i] = new RndVector2D().vec;
         }
     }
 }
Ejemplo n.º 2
0
        public Rocket(RndVector2D rndVector, int lifesp)
        {
            speed.X = rndVector.vec.X;
            speed.Y = rndVector.vec.Y;

            pos.X      = 300;
            pos.Y      = 300;
            Length     = 20;
            endPoint.X = pos.X;
            endPoint.Y = pos.Y + Length;
            Shape      = Vector.Subtract(endPoint, pos);

            TimeCompleted = -1;

            lifespan = lifesp;

            genes = new Dna(lifespan);
        }
Ejemplo n.º 3
0
        public Rocket(int lifesp)
        {
            speed.X = 0;
            speed.Y = 0;

            pos.X      = 300;
            pos.Y      = 300;
            Length     = 20;
            endPoint.X = pos.X;
            endPoint.Y = pos.Y + Length;
            shape.X    = endPoint.X - pos.X;
            shape.Y    = endPoint.Y - pos.Y;

            lifespan      = lifesp;
            TimeCompleted = -1;

            genes = new Dna(lifespan);
        }
Ejemplo n.º 4
0
        public Dna CrossOver(Dna partner)
        {
            Dna newDna = new Dna(lifespan);
            int mid    = RandomGen.rnd.Next(1, genes.Length);

            for (int i = 0; i < genes.Length; i++)
            {
                if (i < mid)
                {
                    newDna.genes[i] = genes[i];
                }
                else
                {
                    newDna.genes[i] = partner.genes[i];
                }
            }

            Mutate(ref newDna);

            return(newDna);
        }