/// <summary> /// Updates the Fitness property by running a landing simulation. /// TODO implement running multiple simulations for varying environments. /// </summary> public void CalculateFitness() { List<double> inputs = new List<double>(); Model.Environment environment = new Model.Environment(); Lander lander = new Lander(environment, this.settings.StartingFuel, this.settings.StartingHorizontal, this.settings.StartingHeight); IList<double> output; for (int i = 0; i < 7; i++) { inputs.Add(0); } this.Fitness = 0; //for (double varWind = -1.0; varWind < 1.0; varWind += 0.1) //{ // this.settings.LanderEnvironment.WindSpeed = varWind; // lander.Enviroment.WindSpeed = varWind; for (double varGravity = 1; varGravity < 3; varGravity += 0.5) { //this.settings.LanderEnvironment.Gravity = varGravity; lander.Enviroment.Gravity = varGravity; lander.Reset(); do { inputs[0] = lander.PositionX; inputs[1] = lander.PositionY; inputs[2] = lander.VelocityX; inputs[3] = lander.VelocityY; inputs[4] = lander.Enviroment.WindSpeed; // this.settings.LanderEnvironment.WindSpeed; inputs[5] = lander.Enviroment.Gravity; // varGravity; // this.settings.LanderEnvironment.Gravity; inputs[6] = lander.Fuel; output = this.neuralNet.Run(inputs); lander.Burn = output[0]; lander.Thrust = output[1]; lander.Update(); //this.settings.LanderEnvironment.Update(); } while (lander.Status == LanderStatus.Flying); this.Fitness += lander.CalculateFitness(); } //} }