예제 #1
0
 //----------------------------------------------------------------------------------------------------------------------
 void ReadCommandLineArgs()
 {
     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);
     }
 }
예제 #2
0
 private static void InitAgentHost()
 {
     _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);
     }
 }
예제 #3
0
        static void Main()
        {
            string missionXML = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no"" ?>
            <Mission xmlns=""http://ProjectMalmo.microsoft.com"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
            
              <About>
                <Summary>Hello world!</Summary>
              </About>
              
            <ServerSection>
              <ServerInitialConditions>
                <Time>
                    <StartTime>1000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <Weather>clear</Weather>
              </ServerInitialConditions>
              <ServerHandlers>
                  <FlatWorldGenerator generatorString=""3;7,44*49,73,35:1,159:4,95:13,35:13,159:11,95:10,159:14,159:6,35:6,95:6;12;""/>
                  <DrawingDecorator>
                    <DrawSphere x=""-27"" y=""70"" z=""0"" radius=""30"" type=""air""/>" + Menger(-40, 40, -13, 27, "stone", "smooth_granite", "air") + @"
                    <DrawCuboid x1=""-25"" y1=""39"" z1=""-2"" x2=""-29"" y2=""39"" z2=""2"" type=""lava""/>
                    <DrawCuboid x1=""-26"" y1=""39"" z1=""-1"" x2=""-28"" y2=""39"" z2=""1"" type=""obsidian""/>
                    <DrawBlock x=""-27"" y=""39"" z=""0"" type=""diamond_block""/>
                  </DrawingDecorator>
                  <ServerQuitFromTimeUp timeLimitMs=""30000""/>
                  <ServerQuitWhenAnyAgentFinishes/>
                </ServerHandlers>
              </ServerSection>
              
              <AgentSection mode=""Survival"">
                <Name>MalmoTutorialBot</Name>
                <AgentStart>
                    <Placement x=""0.5"" y=""56.0"" z=""0.5"" yaw=""90""/>
                    <Inventory>
                        <InventoryItem slot=""8"" type=""diamond_pickaxe""/>
                    </Inventory>
                </AgentStart>
                <AgentHandlers>
                  <ObservationFromFullStats/>
                  <ObservationFromGrid>
                      <Grid name=""floor3x3"">
                        <min x=""-1"" y=""-1"" z=""-1""/>
                        <max x=""1"" y=""-1"" z=""1""/>
                      </Grid>
                  </ObservationFromGrid>
                  <ContinuousMovementCommands turnSpeedDegs=""180""/>
                  <InventoryCommands/>
                  <AgentQuitFromTouchingBlockType>
                      <Block type=""diamond_block"" />
                  </AgentQuitFromTouchingBlockType>
                </AgentHandlers>
              </AgentSection>
            </Mission>";

            // Create default Malmo objects:

            AgentHost agent_host = new AgentHost();

            try
            {
                agent_host.parse(new StringVector(Environment.GetCommandLineArgs()));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:{0}", e.Message);
                Console.WriteLine(agent_host.getUsage());
                Environment.Exit(1);
            }
            if (agent_host.receivedArgument("help"))
            {
                Console.WriteLine(agent_host.getUsage());
                Environment.Exit(0);
            }

            MissionSpec       my_mission        = new MissionSpec(missionXML, true);
            MissionRecordSpec my_mission_record = new MissionRecordSpec();

            // Attempt to start a mission:
            int max_retries = 3;

            for (int retry = 0; retry < max_retries; retry++)
            {
                try
                {
                    agent_host.startMission(my_mission, my_mission_record);
                    break;
                }
                catch (Exception e)
                {
                    if (retry == max_retries - 1)
                    {
                        Console.WriteLine("Error starting mission:{0}", e.Message);
                        Environment.Exit(1);
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
                }
            }

            // Loop until mission starts
            Console.WriteLine("Waiting for the mission to start ");
            WorldState world_state = agent_host.getWorldState();

            while (!world_state.has_mission_begun)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }
            Console.WriteLine();
            Console.WriteLine("Mission running ");

            agent_host.sendCommand("hotbar.9 1"); // Press the hotbar key
            agent_host.sendCommand("hotbar.9 0"); // Release hotbar key - agent should now be holding diamond_pickaxe
            agent_host.sendCommand("pitch 0.2");  // Start looking downward slowly
            Thread.Sleep(1000);                   // Wait a second until we are looking in roughly the right direction
            agent_host.sendCommand("pitch 0");    // Stop tilting the camera
            agent_host.sendCommand("move 1");     // And start running...
            agent_host.sendCommand("attack 1");   // Whilst flailing our pickaxe!
            bool jumping = false;

            // Loop until mission ends:
            while (world_state.is_mission_running)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
                if (world_state.number_of_observations_since_last_state > 0) // Have any observations come in?
                {
                    string  msg          = world_state.observations[world_state.observations.Count - 1].text;
                    JObject observations = JObject.Parse(msg);
                    JToken  grid         = observations.GetValue("floor3x3");
                    if (jumping is true)
                    {
                        if (grid[4].ToString() is "lava")
                        {
                            agent_host.sendCommand("jump 0");
                            jumping = false;
                        }
                    }
                    if (grid[3].ToString() is "lava")
                    {
                        agent_host.sendCommand("jump 1");
                        jumping = true;
                    }
                }
            }
            Console.WriteLine();
            Console.WriteLine("Mission ended");
            // Mission has ended.
        }
예제 #4
0
    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.");
    }
예제 #5
0
파일: Program.cs 프로젝트: vyraun/malmo
    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.");
    }
예제 #6
0
파일: Main.cs 프로젝트: vadimas/events
        private void btnRun_Click(object sender, EventArgs e)
        {
            AgentHost agentHost = new AgentHost();

            try
            {
                agentHost.parse(new StringVector(Environment.GetCommandLineArgs()));
            }
            catch (Exception ex)
            {
                lstMessage.Items.Insert(0, String.Format("ERROR: {0}", ex.Message));
                lstMessage.Items.Insert(0, agentHost.getUsage());
                Environment.Exit(1);
            }
            if (agentHost.receivedArgument("help"))
            {
                lstMessage.Items.Insert(0, agentHost.getUsage());
                Environment.Exit(0);
            }

            // Clear debug box
            lstMessage.Items.Clear();

            // Load the .xml mission file and
            // Run the Mission
            switch (cbSelect.SelectedItem.ToString())
            {
            case "DefaultMission":
                XMLFile = $"{strBaseLocation}DefaultMission.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                DefaultMission.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            case "AvoidTheLava":
                XMLFile = $"{strBaseLocation}AvoidTheLava.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                AvoidTheLava.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            case "Tutorial4":
                XMLFile = $"{strBaseLocation}Tutorial4.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                Tutorial4.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            case "Maze_2":
                XMLFile = $"{strBaseLocation}maze_2.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                maze2.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            case "ObserveExampleOne":
                XMLFile = $"{strBaseLocation}ObserveExampleOne.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                ObserveExampleOne.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            case "TryToNavigateByVideo":
                XMLFile = $"{strBaseLocation}TryToNavigateByVideo.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                TryToNavigateByVideo.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;

            default:
                XMLFile = $"{strBaseLocation}DefaultMission.xml";
                LoadMinecraft(agentHost, XMLFile, lstMessage);
                DefaultMission.Execute(agentHost, lstMessage, pnl3x3, pnlDiagData, pictureBoxMineCraft, chkFullDebug);
                break;
            }
        }
예제 #7
0
        static void Main()
        {
            string missionXML = @"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""no"" ?>
            <Mission xmlns=""http://ProjectMalmo.microsoft.com"" xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"">
            
              <About>
                <Summary>Hello world!</Summary>
              </About>
              
            <ServerSection>
              <ServerInitialConditions>
                <Time>
                    <StartTime>1000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <Weather>clear</Weather>
              </ServerInitialConditions>
              <ServerHandlers>
                  <FlatWorldGenerator generatorString=""3;7,44*49,73,35:1,159:4,95:13,35:13,159:11,95:10,159:14,159:6,35:6,95:6;12;""/>
                  <DrawingDecorator>
                    <DrawSphere x=""-27"" y=""70"" z=""0"" radius=""30"" type=""air""/>" + Menger(-40, 40, -13, 27, "stone", "smooth_granite", "air") + @"
                    <DrawBlock x=""-27"" y=""39"" z=""0"" type=""diamond_block""/>
                  </DrawingDecorator>
                  <ServerQuitFromTimeUp timeLimitMs=""30000""/>
                  <ServerQuitWhenAnyAgentFinishes/>
                </ServerHandlers>
              </ServerSection>
              
              <AgentSection mode=""Survival"">
                <Name>MalmoTutorialBot</Name>
                <AgentStart>
                    <Placement x=""0.5"" y=""56.0"" z=""0.5"" yaw=""90""/>
                    <Inventory>
                        <InventoryItem slot=""8"" type=""diamond_pickaxe""/>
                    </Inventory>
                </AgentStart>
                <AgentHandlers>
                  <ObservationFromFullStats/>
                  <ContinuousMovementCommands turnSpeedDegs=""180""/>
                  <InventoryCommands/>
                  <AgentQuitFromReachingPosition>
                    <Marker x=""-26.5"" y=""40"" z=""0.5"" tolerance=""0.5"" description=""Goal_found""/>
                  </AgentQuitFromReachingPosition>
                </AgentHandlers>
              </AgentSection>
            </Mission>";

            // Create default Malmo objects:

            AgentHost agent_host = new AgentHost();

            try
            {
                agent_host.parse(new StringVector(Environment.GetCommandLineArgs()));
            }
            catch (Exception e)
            {
                Console.WriteLine("Error:{0}", e.Message);
                Console.WriteLine(agent_host.getUsage());
                Environment.Exit(1);
            }
            if (agent_host.receivedArgument("help"))
            {
                Console.WriteLine(agent_host.getUsage());
                Environment.Exit(0);
            }

            MissionSpec       my_mission        = new MissionSpec(missionXML, true);
            MissionRecordSpec my_mission_record = new MissionRecordSpec();

            // Attempt to start a mission:
            int max_retries = 3;

            for (int retry = 0; retry < max_retries; retry++)
            {
                try
                {
                    agent_host.startMission(my_mission, my_mission_record);
                    break;
                }
                catch (Exception e)
                {
                    if (retry == max_retries)
                    {
                        Console.WriteLine("Error starting mission:{0}", e.Message);
                        Environment.Exit(1);
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
                }
            }

            // Loop until mission starts:
            Console.WriteLine("Waiting for the mission to start ");
            WorldState world_state = agent_host.getWorldState();

            while (!world_state.has_mission_begun)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Mission running ");

            agent_host.sendCommand("hotbar.9 1");
            agent_host.sendCommand("hotbar.9 0");

            agent_host.sendCommand("pitch 0.2");
            Thread.Sleep(1000);
            agent_host.sendCommand("pitch 0");
            agent_host.sendCommand("move 1");
            agent_host.sendCommand("attack 1");

            // Loop until mission ends:
            while (world_state.is_mission_running)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }

            Console.WriteLine();
            Console.WriteLine("Mission ended");
            // Mission has ended.
        }
예제 #8
0
파일: Program.cs 프로젝트: CubedCode/malmo
    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.");
    }
예제 #9
0
    public static void Main()
    {
        for (int run = 0; run < 1; run++)
        {
            Console.WriteLine("Run #" + run);

            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);
            }

            bool   pretty_print = false;
            string xml          = System.IO.File.ReadAllText(System.IO.Directory.GetCurrentDirectory() + "/mission.xml");

            MissionSpec mission  = null;
            bool        validate = true;
            mission = new MissionSpec(xml, validate);

            Random rand2 = new Random();

            for (int i = 0; i < rand2.Next(5, 15); i++)
            {
                mission.drawBlock(rand2.Next(1, 10), 46, rand2.Next(1, 10), "red_flower");
            }

            MissionRecordSpec missionRecord = new MissionRecordSpec("./saved_data.tgz");
            missionRecord.recordCommands();
            missionRecord.recordMP4(20, 400000);
            missionRecord.recordRewards();
            missionRecord.recordObservations();

            bool connected = false;
            int  attempts  = 0;
            while (!connected)
            {
                try
                {
                    attempts += 1;
                    agentHost.startMission(mission, missionRecord);
                    connected = true;
                }
                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?");
                    }
                    if (attempts >= 3)   // Give up after three goes.
                    {
                        Environment.Exit(1);
                    }
                    Thread.Sleep(1000); // Wait a second and try again.
                }
            }
            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();

            Queue <JToken> apples   = new Queue <JToken>();
            bool           observed = false;

            // main loop:
            do
            {
                //agentHost.sendCommand(string.Format("turn {0}", rand.NextDouble()));
                Thread.Sleep(500);
                worldState = agentHost.getWorldState();
                //agentHost.sendCommand("pitch 1");
                if (!observed)
                {
                    JObject obj = JObject.Parse(worldState.observations[0].text);

                    JToken entities;

                    if (obj.TryGetValue("close_entities", out entities))
                    {
                        JArray entitiesArr = (JArray)entities;

                        // The first element is always our agent ? - maybe
                        for (int i = 1; i < entitiesArr.Count; i++)
                        {
                            Console.WriteLine(entitiesArr[i]["name"]);
                            if ((string)entitiesArr[i]["name"] == "red_flower")
                            {
                                apples.Enqueue(entitiesArr[i]);
                            }
                        }

                        observed = true;
                    }
                }
                else
                {
                    // Start trying to get to the apples

                    if (apples.Count == 0)
                    {
                        Console.WriteLine("Mission acomplished.");
                        return;
                    }

                    bool popped = false;
                    while (!popped)
                    {
                        var obs = agentHost.getWorldState().observations;
                        if (obs.Count > 0)
                        {
                            // Get our position
                            JObject obj = JObject.Parse(obs[0].text);

                            JToken entities;

                            if (obj.TryGetValue("close_entities", out entities))
                            {
                                JArray entitiesArr = (JArray)entities;

                                // The first element is always our agent ? - maybe
                                Console.WriteLine(entitiesArr[0]);
                                int x = (int)entitiesArr[0]["x"];
                                int z = (int)entitiesArr[0]["z"];

                                int diffX = (int)apples.Peek()["x"] - x;
                                int diffZ = (int)apples.Peek()["z"] - z;

                                Console.WriteLine(diffX + "-" + diffZ);

                                if (diffZ > 0)
                                {
                                    agentHost.sendCommand("movesouth 1");
                                }
                                else if (diffZ < 0)
                                {
                                    agentHost.sendCommand("movenorth 1");
                                }
                                if (diffX > 0)
                                {
                                    agentHost.sendCommand("moveeast 1");
                                }
                                else if (diffX < 0)
                                {
                                    agentHost.sendCommand("movewest 1");
                                }

                                /* Console.WriteLine(entitiesArr[0]);
                                 * if (diffZ > 0)
                                 * {
                                 *   if((float)entitiesArr[0]["yaw"] > 180)
                                 *       agentHost.sendCommand("turn 180");
                                 *   agentHost.sendCommand("move 1");
                                 * }
                                 * else if (diffZ < 0)
                                 * {
                                 *   agentHost.sendCommand("turn 0");
                                 *   agentHost.sendCommand("move 1");
                                 * }
                                 * if (diffX > 0)
                                 * {
                                 *   agentHost.sendCommand("turn -90");
                                 *   agentHost.sendCommand("move 1");
                                 * }
                                 * else if (diffX < 0)
                                 * {
                                 *   agentHost.sendCommand("turn 90");
                                 *   agentHost.sendCommand("move 1");
                                 * }*/

                                if (diffZ == 0 && diffX == 0)
                                {
                                    Console.WriteLine("Dequeuing");
                                    agentHost.sendCommand("move 0");
                                    apples.Dequeue();

                                    // break block
                                    agentHost.sendCommand("pitch 1");
                                    agentHost.sendCommand("attack 1");
                                    agentHost.sendCommand("jump 1");
                                    Thread.Sleep(6000);
                                    break;
                                }
                            }
                        }
                        Thread.Sleep(500);
                        //  agentHost.sendCommand("movenorth 1");
                    }
                }


                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.");
        }
    }
예제 #10
0
        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       my_mission        = new MissionSpec();
            MissionRecordSpec my_mission_record = new MissionRecordSpec("./saved_data.tgz");

            // Attempt to start a mission:
            int max_retries = 3;

            for (int retry = 0; retry < max_retries; retry++)
            {
                try
                {
                    agentHost.startMission(my_mission, my_mission_record);
                    break;
                }
                catch (MissionException ex)
                {
                    if (retry == max_retries - 1)
                    {
                        Console.WriteLine("Error starting mission:{0}", ex.Message);
                        Environment.Exit(1);
                    }
                    else
                    {
                        Thread.Sleep(2000);
                    }
                }
            }
            // Loop until mission starts:
            Console.WriteLine("Waiting for the mission to start ");
            WorldState world_state;

            do
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agentHost.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.Error.WriteLine("Error:{0}", error.text);
                }
            }while (!world_state.has_mission_begun);

            Console.WriteLine();
            Console.WriteLine("Mission running ");
            Console.WriteLine(my_mission.getAsXML(true));

            // Enter your commands here
            // agentHost.sendCommand("turn -0.5");
            // agentHost.sendCommand("move 1");
            // agentHost.sendCommand("jump 1");

            // Loop until mission ends:
            while (world_state.is_mission_running)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agentHost.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }
            Console.WriteLine();
            Console.WriteLine("Mission ended");
            // Mission has ended
        }
예제 #11
0
        static void Main()
        {
            string missionXML = @"<?xml version='1.0' encoding='UTF - 8' standalone='no' ?>
                < Mission xmlns = 'http://ProjectMalmo.microsoft.com' xmlns: xsi = 'http://www.w3.org/2001/XMLSchema-instance' >
  


                      < About >
  

                        < Summary > Hello world!</ Summary >
  

                         </ About >
  


                         < ServerSection >
  

                           < ServerInitialConditions >
  

                               < Time >
  

                                   < StartTime > 12000 </ StartTime >
  

                                   < AllowPassageOfTime > false </ AllowPassageOfTime >
  

                                   < Weather > rain </ Weather >
  

                               </ Time >
  

                           </ ServerInitialConditions >
  

                           < ServerHandlers >
  

                             < FlatWorldGenerator generatorString = '3;7,44*49,73,35:1,159:4,95:13,35:13,159:11,95:10,159:14,159:6,35:6,95:6;12;' />
  

                              < ServerQuitFromTimeUp timeLimitMs = '30000' />
  

                               < ServerQuitWhenAnyAgentFinishes />
  

                             </ ServerHandlers >
  

                           </ ServerSection >
  


                           < AgentSection mode = 'Survival' >
  

                              < Name > MalmoTutorialBot </ Name >
  

                              < AgentStart >
  

                                  < Placement x = '0' y = '56' z = '0' yaw = '90' />
  

                                     </ AgentStart >
  

                                     < AgentHandlers >
  

                                       < ObservationFromFullStats />
  

                                       < ContinuousMovementCommands turnSpeedDegs = '180' />
  

                                      </ AgentHandlers >
  

                                    </ AgentSection >
  

                                  </ Mission >";
            // Create default Malmo objects:

            AgentHost agent_host = new AgentHost();

            try
            {
                agent_host.parse(new StringVector(Environment.GetCommandLineArgs()));
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine("Error:{0}", ex.Message);
                Console.Error.WriteLine(agent_host.getUsage());
                Environment.Exit(1);
            }
            if (agent_host.receivedArgument("help"))
            {
                Console.Error.WriteLine(agent_host.getUsage());
                Environment.Exit(0);
            }

            MissionSpec my_mission = new MissionSpec();

            my_mission.timeLimitInSeconds(30);
            MissionRecordSpec my_mission_record = new MissionRecordSpec("./saved_data.tgz");

            // Attempt to start a mission:
            int max_retries = 3;

            for (int retry = 0; retry < max_retries; retry++)
            {
                try
                {
                    agent_host.startMission(my_mission, my_mission_record);
                    break;
                }
                catch (Exception ex)
                {
                    if (retry == max_retries - 1)
                    {
                        Console.WriteLine("Error starting mission:{0}", ex.Message);
                        Environment.Exit(1);
                    }
                    else
                    {
                        Thread.Sleep(1000);
                    }
                }
            }
            // Loop until mission starts:
            Console.WriteLine("Waiting for the mission to start ");
            WorldState world_state = agent_host.getWorldState();

            while (!world_state.has_mission_begun)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }
            Console.WriteLine();
            Console.WriteLine("Mission running ");

            // Commands go here //

            // Loop until mission ends:
            while (world_state.is_mission_running)
            {
                Console.Write(".");
                Thread.Sleep(100);
                world_state = agent_host.getWorldState();
                foreach (TimestampedString error in world_state.errors)
                {
                    Console.WriteLine("Error:{0}", error.text);
                }
            }
            Console.WriteLine();
            Console.WriteLine("Mission ended");
            // Mission has ended.
        }