コード例 #1
0
        public void StartSimulation(int sessionNumber, bool showOutput = true)
        {
            var sim       = new LanderSimulator();
            var sessionId = network.SessionStart();

            while (sim.Flying)
            {
                var inputs = new List <RlmIOWithValue>();
                inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "fuel"), sim.Fuel.ToString()));
                inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "altitude"), Math.Round(sim.Altitude, 2).ToString()));
                inputs.Add(new RlmIOWithValue(network.Inputs.First(a => a.Name == "velocity"), Math.Round(sim.Velocity, 2).ToString()));

                var cycle = new RlmCycle();
                watcher.Restart();
                var cycleOutcome = cycle.RunCycle(network, network.CurrentSessionID, inputs, Learn);
                watcher.Stop();
                TotalCycleTime.Add(watcher.ElapsedMilliseconds);

                bool thrust = Convert.ToBoolean(cycleOutcome.CycleOutput.Outputs.First(a => a.Name == "thrust").Value);
                if (thrust && showOutput && !Learn)
                {
                    Console.WriteLine("@THRUST");
                }

                var score = scoreTurn(sim, thrust);
                network.ScoreCycle(cycleOutcome.CycleOutput.CycleID, score);

                sim.Turn(thrust);

                if (showOutput && !Learn)
                {
                    Console.WriteLine(sim.Telemetry());
                }

                if (sim.Fuel == 0 && sim.Altitude > 0 && sim.Velocity == -LanderSimulator.TerminalVelocity)
                {
                    break;
                }
            }

            if (showOutput)
            {
                Console.WriteLine($"Session #{ sessionNumber } \t Score: {sim.Score}");
            }

            network.SessionEnd(lastScore = sim.Score);
        }
コード例 #2
0
        public int ScorePilot()
        {
            var sim = new LanderSimulator();

            while (sim.Flying)
            {
                var input = new BasicMLData(3);
                input[0] = _fuelStats.Normalize(sim.Fuel);
                input[1] = _altitudeStats.Normalize(sim.Altitude);
                input[2] = _velocityStats.Normalize(sim.Velocity);
                IMLData output = _network.Compute(input);
                double  value  = output[0];

                bool thrust;

                if (value > 0)
                {
                    thrust = true;
                    if (_track)
                    {
                        Console.WriteLine(@"THRUST");
                    }
                }
                else
                {
                    thrust = false;
                }

                sim.Turn(thrust);
                if (_track)
                {
                    Console.WriteLine(sim.Telemetry());
                }
            }

            CycleCount++;

            Outputs.Add(new EncogSimOut {
                Session = CycleCount, Score = sim.Score
            });

            return(sim.Score);
        }
コード例 #3
0
        public double scoreTurn(LanderSimulator sim, bool thrust)
        {
            double retVal = 0;

            if (sim.Altitude <= 1000)
            {
                if (sim.Fuel > 0 && sim.Velocity >= -5 && !thrust)
                {
                    retVal = sim.Fuel;
                }
                else if (sim.Fuel > 0 && sim.Velocity < -5 && thrust)
                {
                    retVal = sim.Fuel;
                }
            }
            else if (sim.Altitude > 1000 && !thrust)
            {
                retVal = 200;
            }

            return(retVal);
        }