コード例 #1
0
ファイル: UnitTest1.cs プロジェクト: josharmstrong08/Lander
 public void SanityCheck()
 {
     // Check that the lander will crash with the default settings
     LanderSimulator.Model.Environment environment = new LanderSimulator.Model.Environment();
     LanderSimulator.Model.Lander lander = new LanderSimulator.Model.Lander(environment, 100, 0, 100);
     bool crashed = false;
     for (int i = 0; i < 100; i++)
     {
         if (lander.Update() == LanderStatus.Crashed)
         {
             crashed = true;
             break;
         }
     }
     Assert.IsTrue(crashed);
 }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the MainViewModel class.
        /// </summary>
        public MainViewModel()
        {
            this.environment = new LanderSimulator.Model.Environment();
            this.lander = new LanderSimulator.Model.Lander(this.environment, 100, 0, 100);
            timer = new Timer(10);
            timer.Elapsed += new ElapsedEventHandler(UpdateLanderPosition);
            timer.AutoReset = true;
            this.LanderPositionX = this.lander.PositionX;
            this.LanderPositionY = this.lander.PositionY;

            this.MinFitnessValues = new ObservableCollection<Tuple<int, double>>();
            this.MaxFitnessValues = new ObservableCollection<Tuple<int, double>>();
            this.AvgFitnessValues = new ObservableCollection<Tuple<int, double>>();

            this.ExecuteTrainCommand();
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: josharmstrong08/Lander
        /// <summary>
        /// Runs the simulation with given starting variables.
        /// </summary>
        /// <returns></returns>
        private static LanderStatus RunOneSimulation(bool showOutput, double positionx, double positiony,
            double fuel, double windspeed, double gravity)
        {
            // First query the neural net to see how it reacts to the current conditions.
            // Then update the conditions.
            bool stop = false;

            if (showOutput)
            {
                Console.WriteLine("(X,Y,Vx,Vy,Fuel,Wind,Gravity) => (Burn,Thrust)");
            }

            LanderSimulator.Model.Environment env = new LanderSimulator.Model.Environment();
            env.Gravity = gravity;
            env.WindSpeed = windspeed;
            LanderSimulator.Model.Lander lander = new LanderSimulator.Model.Lander(env, fuel, positionx, positiony);

            while (stop == false)
            {
                // height, xPosition, Yvelocity, Xvelocity, wind, acceleration, and fuel.
                List<double> inputs = new List<double>();
                inputs.Add(lander.PositionX);
                inputs.Add(lander.PositionY);
                inputs.Add(lander.VelocityX);
                inputs.Add(lander.VelocityY);
                inputs.Add(env.WindSpeed);
                inputs.Add(env.Gravity);
                inputs.Add(lander.Fuel);

                IList<double> output = neuralNetwork.Run(inputs);

                lander.Burn = output[0];
                lander.Thrust = output[1];

                lander.Update();

                if (lander.Status != LanderSimulator.Model.LanderStatus.Flying)
                {
                    stop = true;
                }

                if (showOutput)
                {
                    Console.CursorLeft = 0;
                    switch (lander.Status)
                    {
                        case LanderSimulator.Model.LanderStatus.Flying:
                            Console.BackgroundColor = ConsoleColor.Black;
                            Console.Write("Flying:  ");
                            Console.BackgroundColor = ConsoleColor.Black;
                            break;
                        case LanderSimulator.Model.LanderStatus.Landed:
                            Console.BackgroundColor = ConsoleColor.Green;
                            Console.ForegroundColor = ConsoleColor.Black;
                            Console.Write("Landed:  ");
                            Console.BackgroundColor = ConsoleColor.Black;
                            Console.ForegroundColor = ConsoleColor.Gray;
                            break;
                        case LanderSimulator.Model.LanderStatus.Crashed:
                            Console.BackgroundColor = ConsoleColor.Red;
                            Console.Write("Crashed: ");
                            Console.BackgroundColor = ConsoleColor.Black;
                            break;
                    }

                    Console.Write("({0,6:f2},{1,6:f2},{2,6:f2},{3,6:f2},{4,6:f2},{5,6:f2},{6,6:f2}) => ({7,6:f2},{8,6:f2})",
                        lander.PositionX, lander.PositionY, lander.VelocityX, lander.VelocityY, lander.Fuel,
                        env.WindSpeed, env.Gravity, output[0], output[1]);
                    Thread.Sleep(250);
                }

                env.Update();
            }

            if (showOutput)
            {
                Console.WriteLine();
                Console.WriteLine("Fitness: {0:f3}", lander.CalculateFitness());
            }

            return lander.Status;
        }