private static void InitMissionSpecs() { var missionXmlDefinition = File.ReadAllText("SampleMission.xml"); _mission = new MissionSpec(missionXmlDefinition, false); _mission.requestVideo(640, 480); var recordedFileName = $"./mission_data{DateTime.Now:hh mm ss}.tgz"; _missionRecord = new MissionRecordSpec(recordedFileName); _missionRecord.recordCommands(); _missionRecord.recordMP4(20, 400000); _missionRecord.recordRewards(); _missionRecord.recordObservations(); }
public static void Main(string[] args) { MissionSpec my_mission = new MissionSpec(); my_mission.timeLimitInSeconds(10); my_mission.drawBlock(19, 0, 19, "redstone_block"); my_mission.createDefaultTerrain(); my_mission.setTimeOfDay(6000, false); my_mission.drawCuboid(50, 0, 50, 100, 10, 100, "redstone_block"); my_mission.drawItem(3, 0, 2, "diamond_pickaxe"); my_mission.drawSphere(50, 10, 50, 10, "ice"); my_mission.drawLine(50, 20, 50, 100, 20, 100, "redstone_block"); my_mission.startAt(2.5f, 0.0f, 2.5f); my_mission.endAt(19.5f, 0.0f, 19.5f, 1.0f); my_mission.requestVideo(320, 240); my_mission.setModeToCreative(); my_mission.rewardForReachingPosition(19.5f, 0.0f, 19.5f, 100.0f, 1.1f); my_mission.observeRecentCommands(); my_mission.observeHotBar(); my_mission.observeFullInventory(); my_mission.observeGrid(-2, 0, -2, 2, 1, 2, "Cells"); my_mission.observeDistance(19.5f, 0.0f, 19.5f, "Goal"); my_mission.allowAllDiscreteMovementCommands(); // check that the XML we produce validates bool pretty_print = false; string xml = my_mission.getAsXML(pretty_print); try { bool validate = true; MissionSpec my_mission2 = new MissionSpec(xml, validate); // check that we get the same XML if we go round again string xml2 = my_mission2.getAsXML(pretty_print); if (xml2 != xml) { Console.WriteLine("Mismatch between first generation XML and the second."); Environment.Exit(1); } } catch (Exception e) { Console.WriteLine("Error validating the XML we generated: {0}", e); Environment.Exit(1); } }
private async Task <MissionSpec> loadMission(string path) { using (StreamReader reader = new StreamReader(path)) { try { string xml = await reader.ReadToEndAsync(); xml = xml.Replace("__SEED__", _rand.Next().ToString()); MissionSpec mission = new MissionSpec(xml, true); if (!mission.isVideoRequested(0)) { mission.requestVideo(Settings.Default.VideoWidth, Settings.Default.VideoHeight); } mission.removeAllCommandHandlers(); mission.allowAllContinuousMovementCommands(); mission.allowAllDiscreteMovementCommands(); XDocument xdoc = XDocument.Parse(xml); XNamespace malmo = "http://ProjectMalmo.microsoft.com"; var timeUpNode = xdoc.Descendants(malmo + "ServerQuitFromTimeUp").FirstOrDefault(); if (timeUpNode != null) { _missionDuration = TimeSpan.FromMilliseconds(double.Parse(timeUpNode.Attribute("timeLimitMs").Value)); } else { _missionDuration = TimeSpan.Zero; } if (_recordWindow != null && _recordWindow.IsVisible) { _recordWindow.MissionPath = path; } return(mission); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing Mission", MessageBoxButton.OK, MessageBoxImage.Error); return(null); } } }
private static void LoadMinecraft(AgentHost agentHost, string XMLFile, ListBox lstMessage) { String strXMLFileContents = ""; using (StreamReader sr = new StreamReader(XMLFile)) { // Read the stream to a string, and write the string to the console. strXMLFileContents = sr.ReadToEnd(); } MissionSpec mission = new MissionSpec(strXMLFileContents, false); mission.requestVideo(640, 480); MissionRecordSpec missionRecord = new MissionRecordSpec("./saved_data.tgz"); missionRecord.recordCommands(); missionRecord.recordMP4(20, 400000); missionRecord.recordRewards(); missionRecord.recordObservations(); try { agentHost.startMission(mission, missionRecord); } catch (Exception ex) { lstMessage.Items.Insert(0, String.Format("Error starting mission: {0}", ex.Message)); Environment.Exit(1); } WorldState worldState; lstMessage.Items.Insert(0, "Waiting for the mission to start"); do { Thread.Sleep(100); worldState = agentHost.getWorldState(); foreach (TimestampedString error in worldState.errors) { lstMessage.Items.Insert(0, String.Format("Error: {0}", error.text)); } }while (!worldState.has_mission_begun); }
public static void Main(string[] args) { MissionSpec my_mission = new MissionSpec(); my_mission.timeLimitInSeconds( 10 ); my_mission.drawBlock( 19, 0, 19, "redstone_block" ); my_mission.createDefaultTerrain(); my_mission.setTimeOfDay(6000,false); my_mission.drawCuboid(50,0,50,100,10,100,"redstone_block"); my_mission.drawItem(3,0,2,"diamond_pickaxe"); my_mission.drawSphere(50,10,50,10,"ice"); my_mission.drawLine(50,20,50,100,20,100,"redstone_block"); my_mission.startAt( 2.5f, 0.0f, 2.5f ); my_mission.endAt( 19.5f, 0.0f, 19.5f, 1.0f ); my_mission.requestVideo( 320, 240 ); my_mission.setModeToCreative(); my_mission.rewardForReachingPosition(19.5f,0.0f,19.5f,100.0f,1.1f); my_mission.observeRecentCommands(); my_mission.observeHotBar(); my_mission.observeFullInventory(); my_mission.observeGrid(-2,0,-2,2,1,2,"Cells"); my_mission.observeDistance(19.5f,0.0f,19.5f,"Goal"); my_mission.allowAllDiscreteMovementCommands(); // check that the XML we produce validates bool pretty_print = false; string xml = my_mission.getAsXML( pretty_print ); try { bool validate = true; MissionSpec my_mission2 = new MissionSpec( xml, validate ); // check that we get the same XML if we go round again string xml2 = my_mission2.getAsXML( pretty_print ); if( xml2 != xml ) { Console.WriteLine("Mismatch between first generation XML and the second."); Environment.Exit(1); } } catch( Exception e ) { Console.WriteLine("Error validating the XML we generated: {0}", e); Environment.Exit(1); } }
private void TryStartMission() { try { mission.requestVideo(320, 240); mission.setViewpoint(1); var outputDirectory = FileUtility.CreateOutputDirectory(userName, folderName); MissionRecordSpec missionRecord = new MissionRecordSpec(outputDirectory + "data.tgz"); missionRecord.recordMP4(60, 400000); agentHost.startMission(mission, availableClients, missionRecord, 0, "Test Builder"); } catch (Exception ex) { string errorLine = "Fatal error when starting a mission in ProgramMalmo: " + ex.Message; Console.WriteLine("Error starting mission: {0}", ex.Message); Environment.Exit(1); } }
private async Task<MissionSpec> loadMission(string path) { using (StreamReader reader = new StreamReader(path)) { try { string xml = await reader.ReadToEndAsync(); xml = xml.Replace("__SEED__", _rand.Next().ToString()); MissionSpec mission = new MissionSpec(xml, true); if (!mission.isVideoRequested(0)) { mission.requestVideo(Settings.Default.VideoWidth, Settings.Default.VideoHeight); } mission.removeAllCommandHandlers(); mission.allowAllContinuousMovementCommands(); mission.allowAllDiscreteMovementCommands(); XDocument xdoc = XDocument.Parse(xml); XNamespace malmo = "http://ProjectMalmo.microsoft.com"; var timeUpNode = xdoc.Descendants(malmo + "ServerQuitFromTimeUp").FirstOrDefault(); if(timeUpNode != null) { _missionDuration = TimeSpan.FromMilliseconds(double.Parse(timeUpNode.Attribute("timeLimitMs").Value)); } else { _missionDuration = TimeSpan.Zero; } if (_recordWindow != null && _recordWindow.IsVisible) { _recordWindow.MissionPath = path; } return mission; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error Parsing Mission", MessageBoxButton.OK, MessageBoxImage.Error); return null; } } }
public static void Main() { AgentHost agentHost = new AgentHost(); try { agentHost.parse(new StringVector(Environment.GetCommandLineArgs())); } catch (Exception ex) { Console.Error.WriteLine("ERROR: {0}", ex.Message); Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(1); } if (agentHost.receivedArgument("help")) { Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(0); } MissionSpec mission = new MissionSpec(); mission.timeLimitInSeconds(10); mission.requestVideo(320, 240); mission.rewardForReachingPosition(19.5f, 0.0f, 19.5f, 100.0f, 1.1f); MissionRecordSpec missionRecord = new MissionRecordSpec("./saved_data.tgz"); missionRecord.recordCommands(); missionRecord.recordMP4(20, 400000); missionRecord.recordRewards(); missionRecord.recordObservations(); try { agentHost.startMission(mission, missionRecord); } catch (MissionException ex) { // Using catch(Exception ex) would also work, but specifying MissionException allows // us to access the error code: Console.Error.WriteLine("Error starting mission: {0}", ex.Message); Console.Error.WriteLine("Error code: {0}", ex.getMissionErrorCode()); // We can do more specific error handling using this code, eg: if (ex.getMissionErrorCode() == MissionException.MissionErrorCode.MISSION_INSUFFICIENT_CLIENTS_AVAILABLE) { Console.Error.WriteLine("Have you started a Minecraft client?"); } Environment.Exit(1); } WorldState worldState; Console.WriteLine("Waiting for the mission to start"); do { Console.Write("."); Thread.Sleep(100); worldState = agentHost.getWorldState(); foreach (TimestampedString error in worldState.errors) { Console.Error.WriteLine("Error: {0}", error.text); } }while (!worldState.has_mission_begun); Console.WriteLine(); Random rand = new Random(); // main loop: do { agentHost.sendCommand("move 1"); agentHost.sendCommand(string.Format("turn {0}", rand.NextDouble())); Thread.Sleep(500); worldState = agentHost.getWorldState(); Console.WriteLine( "video,observations,rewards received: {0}, {1}, {2}", worldState.number_of_video_frames_since_last_state, worldState.number_of_observations_since_last_state, worldState.number_of_rewards_since_last_state); foreach (TimestampedReward reward in worldState.rewards) { Console.Error.WriteLine("Summed reward: {0}", reward.getValue()); } foreach (TimestampedString error in worldState.errors) { Console.Error.WriteLine("Error: {0}", error.text); } }while (worldState.is_mission_running); Console.WriteLine("Mission has stopped."); }
public static void Main() { AgentHost agentHost = new AgentHost(); try { agentHost.parse(new StringVector(Environment.GetCommandLineArgs())); } catch (Exception ex) { Console.Error.WriteLine("ERROR: {0}", ex.Message); Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(1); } if (agentHost.receivedArgument("help")) { Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(0); } MissionSpec mission = new MissionSpec(); mission.timeLimitInSeconds(10); mission.requestVideo(320, 240); mission.rewardForReachingPosition(19.5f, 0.0f, 19.5f, 100.0f, 1.1f); MissionRecordSpec missionRecord = new MissionRecordSpec("./saved_data.tgz"); missionRecord.recordCommands(); missionRecord.recordMP4(20, 400000); missionRecord.recordRewards(); missionRecord.recordObservations(); try { agentHost.startMission(mission, missionRecord); } catch (Exception ex) { Console.Error.WriteLine("Error starting mission: {0}", ex.Message); Environment.Exit(1); } WorldState worldState; Console.WriteLine("Waiting for the mission to start"); do { Console.Write("."); Thread.Sleep(100); worldState = agentHost.getWorldState(); foreach (TimestampedString error in worldState.errors) { Console.Error.WriteLine("Error: {0}", error.text); } }while (!worldState.is_mission_running); Console.WriteLine(); Random rand = new Random(); // main loop: do { agentHost.sendCommand("move 1"); agentHost.sendCommand(string.Format("turn {0}", rand.NextDouble())); Thread.Sleep(500); worldState = agentHost.getWorldState(); Console.WriteLine( "video,observations,rewards received: {0}, {1}, {2}", worldState.number_of_video_frames_since_last_state, worldState.number_of_observations_since_last_state, worldState.number_of_rewards_since_last_state); foreach (TimestampedReward reward in worldState.rewards) { Console.Error.WriteLine("Summed reward: {0}", reward.getValue()); } foreach (TimestampedString error in worldState.errors) { Console.Error.WriteLine("Error: {0}", error.text); } }while (worldState.is_mission_running); Console.WriteLine("Mission has stopped."); }
public static void Main() { AgentHost agentHost = new AgentHost(); try { agentHost.parse( new StringVector( Environment.GetCommandLineArgs() ) ); } catch( Exception ex ) { Console.Error.WriteLine("ERROR: {0}", ex.Message); Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(1); } if( agentHost.receivedArgument("help") ) { Console.Error.WriteLine(agentHost.getUsage()); Environment.Exit(0); } MissionSpec mission = new MissionSpec(); mission.timeLimitInSeconds(10); mission.requestVideo( 320, 240 ); mission.rewardForReachingPosition(19.5f,0.0f,19.5f,100.0f,1.1f); MissionRecordSpec missionRecord = new MissionRecordSpec("./saved_data.tgz"); missionRecord.recordCommands(); missionRecord.recordMP4(20, 400000); missionRecord.recordRewards(); missionRecord.recordObservations(); try { agentHost.startMission(mission, missionRecord); } catch (Exception ex) { Console.Error.WriteLine("Error starting mission: {0}", ex.Message); Environment.Exit(1); } WorldState worldState; Console.WriteLine("Waiting for the mission to start"); do { Console.Write("."); Thread.Sleep(100); worldState = agentHost.getWorldState(); foreach (TimestampedString error in worldState.errors) Console.Error.WriteLine("Error: {0}", error.text); } while (!worldState.is_mission_running); Console.WriteLine(); Random rand = new Random(); // main loop: do { agentHost.sendCommand("move 1"); agentHost.sendCommand(string.Format("turn {0}", rand.NextDouble())); Thread.Sleep(500); worldState = agentHost.getWorldState(); Console.WriteLine( "video,observations,rewards received: {0}, {1}, {2}", worldState.number_of_video_frames_since_last_state, worldState.number_of_observations_since_last_state, worldState.number_of_rewards_since_last_state); foreach (TimestampedReward reward in worldState.rewards) Console.Error.WriteLine("Summed reward: {0}", reward.getValue()); foreach (TimestampedString error in worldState.errors) Console.Error.WriteLine("Error: {0}", error.text); } while (worldState.is_mission_running); Console.WriteLine("Mission has stopped."); }
public static void Main(string[] args) { MissionSpec my_mission = new MissionSpec(); my_mission.setSummary("example mission"); my_mission.timeLimitInSeconds(10); my_mission.drawBlock(19, 0, 19, "redstone_block"); my_mission.createDefaultTerrain(); my_mission.setTimeOfDay(6000, false); my_mission.drawCuboid(50, 0, 50, 100, 10, 100, "redstone_block"); my_mission.drawItem(3, 0, 2, "diamond_pickaxe"); my_mission.drawSphere(50, 10, 50, 10, "ice"); my_mission.drawLine(50, 20, 50, 100, 20, 100, "redstone_block"); my_mission.startAt(2.5f, 0.0f, 2.5f); my_mission.endAt(19.5f, 0.0f, 19.5f, 1.0f); my_mission.requestVideo(320, 240); my_mission.setModeToCreative(); my_mission.rewardForReachingPosition(19.5f, 0.0f, 19.5f, 100.0f, 1.1f); my_mission.observeRecentCommands(); my_mission.observeHotBar(); my_mission.observeFullInventory(); my_mission.observeGrid(-2, 0, -2, 2, 1, 2, "Cells"); my_mission.observeDistance(19.5f, 0.0f, 19.5f, "Goal"); my_mission.removeAllCommandHandlers(); my_mission.allowContinuousMovementCommand("move"); my_mission.allowContinuousMovementCommand("strafe"); my_mission.allowDiscreteMovementCommand("movenorth"); my_mission.allowInventoryCommand("swapInventoryItems"); if (my_mission.getSummary() != "example mission") { Console.WriteLine("Unexpected summary"); Environment.Exit(1); } string[] expected_command_handlers = { "ContinuousMovement", "DiscreteMovement", "Inventory" }; string[] actual_command_handlers = new List <string>(my_mission.getListOfCommandHandlers(0)).ToArray(); if (actual_command_handlers.Length != expected_command_handlers.Length) { Console.WriteLine("Number of command handlers mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_command_handlers.Length; i++) { if (!actual_command_handlers[i].Equals(expected_command_handlers[i])) { Console.WriteLine("Unexpected command handler: {0}", actual_command_handlers[i]); Environment.Exit(1); } } string[] expected_continuous_commands = { "move", "strafe" }; string[] actual_continuous_commands = new List <string>(my_mission.getAllowedCommands(0, "ContinuousMovement")).ToArray(); if (actual_continuous_commands.Length != expected_continuous_commands.Length) { Console.WriteLine("Number of continuous commands mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_continuous_commands.Length; i++) { if (!actual_continuous_commands[i].Equals(expected_continuous_commands[i])) { Console.WriteLine("Unexpected continuous command: {0}", actual_continuous_commands[i]); Environment.Exit(1); } } string[] expected_discrete_commands = { "movenorth" }; string[] actual_discrete_commands = new List <string>(my_mission.getAllowedCommands(0, "DiscreteMovement")).ToArray(); if (actual_discrete_commands.Length != expected_discrete_commands.Length) { Console.WriteLine("Number of discrete commands mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_discrete_commands.Length; i++) { if (!actual_discrete_commands[i].Equals(expected_discrete_commands[i])) { Console.WriteLine("Unexpected discrete command: {0}", actual_discrete_commands[i]); Environment.Exit(1); } } string[] expected_inventory_commands = { "swapInventoryItems" }; string[] actual_inventory_commands = new List <string>(my_mission.getAllowedCommands(0, "Inventory")).ToArray(); if (actual_inventory_commands.Length != expected_inventory_commands.Length) { Console.WriteLine("Number of commands mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_inventory_commands.Length; i++) { if (!actual_inventory_commands[i].Equals(expected_inventory_commands[i])) { Console.WriteLine("Unexpected command: {0}", actual_inventory_commands[i]); Environment.Exit(1); } } // check that the XML we produce validates bool pretty_print = false; string xml = my_mission.getAsXML(pretty_print); try { bool validate = true; MissionSpec my_mission2 = new MissionSpec(xml, validate); // check that we get the same XML if we go round again string xml2 = my_mission2.getAsXML(pretty_print); if (xml2 != xml) { Console.WriteLine("Mismatch between first generation XML and the second."); Environment.Exit(1); } } catch (Exception e) { Console.WriteLine("Error validating the XML we generated: {0}", e); Environment.Exit(1); } // check that known-good XML validates const string xml3 = @"<?xml version=""1.0"" encoding=""UTF-8"" ?><Mission xmlns=""http://ProjectMalmo.microsoft.com"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""> <About><Summary>Run the maze!</Summary></About> <ServerSection><ServerInitialConditions><AllowSpawning>true</AllowSpawning><Time><StartTime>1000</StartTime><AllowPassageOfTime>true</AllowPassageOfTime></Time><Weather>clear</Weather></ServerInitialConditions> <ServerHandlers> <FlatWorldGenerator generatorString=""3;7,220*1,5*3,2;3;,biome_1"" /> <ServerQuitFromTimeUp timeLimitMs=""20000"" /> <ServerQuitWhenAnyAgentFinishes /> </ServerHandlers></ServerSection> <AgentSection><Name>Jason Bourne</Name><AgentStart><Placement x=""-204"" y=""81"" z=""217""/></AgentStart><AgentHandlers> <VideoProducer want_depth=""true""><Width>320</Width><Height>240</Height></VideoProducer> <RewardForReachingPosition><Marker reward=""100"" tolerance=""1.1"" x=""-104"" y=""81"" z=""217""/></RewardForReachingPosition> <ContinuousMovementCommands><ModifierList type=""deny-list""><command>attack</command><command>crouch</command></ModifierList></ContinuousMovementCommands> <AgentQuitFromReachingPosition><Marker x=""-104"" y=""81"" z=""217""/></AgentQuitFromReachingPosition> </AgentHandlers></AgentSection></Mission>"; try { const bool validate = true; MissionSpec my_mission3 = new MissionSpec(xml3, validate); if (my_mission3.getSummary() != "Run the maze!") { Console.WriteLine("Unexpected summary"); Environment.Exit(1); } string[] expected_command_handlers2 = { "ContinuousMovement" }; string[] actual_command_handlers2 = new List <string>(my_mission3.getListOfCommandHandlers(0)).ToArray(); if (actual_command_handlers2.Length != expected_command_handlers2.Length) { Console.WriteLine("Number of command handlers mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_command_handlers2.Length; i++) { if (!actual_command_handlers2[i].Equals(expected_command_handlers2[i])) { Console.WriteLine("Unexpected command handler: {0}", actual_command_handlers2[i]); Environment.Exit(1); } } string[] expected_continuous_commands2 = { "jump", "move", "pitch", "strafe", "turn", "use" }; string[] actual_continuous_commands2 = new List <string>(my_mission3.getAllowedCommands(0, "ContinuousMovement")).ToArray(); if (actual_continuous_commands2.Length != expected_continuous_commands2.Length) { Console.WriteLine("Number of continuous commands mismatch"); Environment.Exit(1); } for (int i = 0; i < actual_continuous_commands2.Length; i++) { if (!actual_continuous_commands2[i].Equals(expected_continuous_commands2[i])) { Console.WriteLine("Unexpected continuous command: {0}", actual_continuous_commands2[i]); Environment.Exit(1); } } } catch (Exception e) { Console.WriteLine("Error validating known-good XML: {0}", e); Environment.Exit(1); } }