예제 #1
0
 void RunMalmo()
 {
     // Normally we do not need this line, but we will Dispose() agentHost at the end
     // of the method because of a bug in Malmo.
     agentHost = new AgentHost();
     CreateResetNetworkEvent();
     // Deactivated for published version
     //ReadCommandLineArgs();
     InitializeMission();
     System.Diagnostics.Debug.WriteLine("Mission initialized");
     if (!TryStartMission())
     {
         CreateMissionEndEvent();
         return;
     }
     ConsoleOutputWhileMissionLoads();
     MainLoop();
     // We need to destroy the agentHost so that the data is saved. This is a bug in Malmo.
     agentHost.Dispose();
     System.Diagnostics.Debug.WriteLine("Mission has stopped.");
     // Extracts the results and moves the video to the candidates folder:
     SharpNeat.PopulationReadWrite.CreateCandidateVideoFromResults(fileName, userName);
     CreateMissionEndEvent();
 }
예제 #2
0
        public void RunMalmo(IBlackBox brain)
        {
            agentHost  = new AgentHost();
            neatPlayer = new NeatAgentController(brain, agentHost);

            InitializeMission();

            CreateWorld();
            TryStartMission();

            ConsoleOutputWhileMissionLoads();

            //set agent stuck bool
            neatPlayer.AgentNotStuck = true;

            Console.WriteLine("Mission has started!");

            var  agentPosition    = new AgentPosition();
            bool gotStartPosition = false;

            Thread.Sleep(500);

            while (worldState.is_mission_running)
            {
                //Early termination of mission in case no action was performed (agent is stuck)
                if (!neatPlayer.AgentNotStuck)
                {
                    //Ensures that the video is at least 2 seconds long, showing the users that no action actually was performed
                    Thread.Sleep(2000);

                    neatPlayer.AgentHelper.endMission();
                    break;
                }

                //Give observations to agent and let agent perform actions according to these
                worldState = agentHost.getWorldState();
                if (worldState.observations.Count == 0)
                {
                    continue;
                }
                neatPlayer.AgentHelper.ConstantObservations = worldState.observations;
                neatPlayer.PerformAction();

                //Get end position and fitness grid after every performed action by the agent
                if (worldState.observations != null)
                {
                    var observations = JObject.Parse(worldState.observations[0].text);

                    if (!gotStartPosition)
                    {
                        agentPosition.initialX = (double)observations.GetValue("XPos");
                        agentPosition.initialY = (double)observations.GetValue("YPos");
                        agentPosition.initialZ = (double)observations.GetValue("ZPos");

                        gotStartPosition = true;
                    }

                    agentPosition.currentX = (double)observations.GetValue("XPos");
                    agentPosition.currentY = (double)observations.GetValue("YPos");
                    agentPosition.currentZ = (double)observations.GetValue("ZPos");
                }
            }

            neatPlayer.AgentHelper.AgentPosition = agentPosition;

            Thread.Sleep(2000);
            agentHost.Dispose();

            Console.WriteLine("Mission has ended!");
        }