Example #1
0
        public Car(Road road, CarGenotype genotype)
        {
            Genotype = genotype;
            Sprite   = new Sprite(carTexture)
            {
                Origin   = new Vector2f(carTexture.Size.X / 2, carTexture.Size.Y / 2),
                Position = new Vector2f(100, 50)
            };

            Sensors = new List <Sensor>()
            {
                new Sensor(road, this, new Vector2f(1, 0)),
                new Sensor(road, this, new Vector2f(0.5f, 0.2f)),
                new Sensor(road, this, new Vector2f(0.5f, -0.2f)),
                new Sensor(road, this, new Vector2f(0.5f, 0.6f)),
                new Sensor(road, this, new Vector2f(0.5f, -0.6f))
            }.AsReadOnly();
        }
Example #2
0
        public IGenotype Mutation(float mutationProb, float mutationAmount)
        {
            var newGenotype = new CarGenotype(this);

            for (int i = 0; i < Parameters.Length; i++)
            {
                if (Randomizer.NextDouble() <= mutationProb)
                {
                    newGenotype.Parameters[i] += Randomizer.NextDouble() * (mutationAmount * 2) - mutationAmount;
                    if (newGenotype.Parameters[i] > 1)
                    {
                        newGenotype.Parameters[i] = 1;
                    }
                    else if (newGenotype.Parameters[i] < -1)
                    {
                        newGenotype.Parameters[i] = -1;
                    }
                }
            }

            return(newGenotype);
        }
Example #3
0
 public CarGenotype(CarGenotype carGenotype)
 {
     carGenotype.Parameters.CopyTo(Parameters, 0);
 }