Esempio n. 1
0
 public bool equal(Gene g)
 {
     if (g.x != x)
     {
         return(false);
     }
     if (g.y != y)
     {
         return(false);
     }
     if (g.repeatX != repeatX)
     {
         return(false);
     }
     if (g.repeatY != repeatY)
     {
         return(false);
     }
     if (g.terrain != terrain)
     {
         return(false);
     }
     return(true);
 }
Esempio n. 2
0
        public void mutate(Genotype g, Random r)
        {
            G.mutationCount++;
            Random rnd = new Random();
            int    x   = rnd.Next(0, Params.genotypeSize);

            // this rolls a new gene
            g.genes[x] = new Gene(r);


            //this amkes a small change to x & y
            x = rnd.Next(0, Params.genotypeSize);
            if (G.rnd.NextDouble() < 0.5)
            {
                if (g.genes[x].x < Params.dimX)
                {
                    g.genes[x].x++;
                }
                if (g.genes[x].y < Params.dimY)
                {
                    g.genes[x].y++;
                }
            }
            else
            {
                if (g.genes[x].x > 0)
                {
                    g.genes[x].x--;
                }
                if (g.genes[x].y > 0)
                {
                    g.genes[x].y--;
                }
            }
            //small cahnge to x and y repeat
            x = rnd.Next(0, Params.genotypeSize);
            if (G.rnd.NextDouble() < 0.5)
            {
                if (g.genes[x].repeatX < Params.maxRepeat)
                {
                    g.genes[x].repeatX++;
                }
                if (g.genes[x].y < Params.maxRepeat)
                {
                    g.genes[x].repeatX++;
                }
            }
            else
            {
                if (g.genes[x].x > 0)
                {
                    g.genes[x].repeatX--;
                }
                if (g.genes[x].y > 0)
                {
                    g.genes[x].repeatY--;
                }
            }
            //swap two of the genes to make em random :L
            x = rnd.Next(0, Params.genotypeSize / 2);
            Gene temp = g.genes[x];
            int  y    = rnd.Next(Params.genotypeSize / 2, Params.genotypeSize);

            g.genes[x]         = g.genes[y];
            g.genes[x].terrain = 1;
            // if (g.genes[x].repeatX < Params.maxRepeat)
            //   g.genes[x].re
        }