예제 #1
0
        private void LanderGui_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
            case Keys.W:
                _lander.IsMainEngineFiring = true;
                break;

            case Keys.A:
                _lander.IsRightThrusterFiring = true;
                break;

            case Keys.D:
                _lander.IsLeftThrusterFiring = true;
                break;

            case Keys.Space:
                _lander.Halt();
                break;

            case Keys.F5:
                _lander.Reset();
                break;
            }
        }
예제 #2
0
        /// <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();
                }
            //}
        }