Exemple #1
0
def GetMissionXML(mazeblock, agent_host):
    return '''<?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>
        
        <ModSettings>
            <MsPerTick>''' + str(TICK_LENGTH) + '''</MsPerTick>
        </ModSettings>

        <ServerSection>
            <ServerInitialConditions>
                <AllowSpawning>false</AllowSpawning>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                ''' + mazeblock + '''
                <ServerQuitFromTimeUp timeLimitMs="45000"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>James Bond</Name>
            <AgentStart>
                <Placement x="-204" y="81" z="217"/>
            </AgentStart>
            <AgentHandlers>
                <ContinuousMovementCommands turnSpeedDegs="840">
                    <ModifierList type="deny-list"> <!-- Example deny-list: prevent agent from strafing -->
                        <command>strafe</command>
                    </ModifierList>
                </ContinuousMovementCommands>''' + malmoutils.get_video_xml(
        agent_host) + '''
Exemple #2
0
def GetMissionXML( mazeblock, agent_host ):
    return '''<?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>
        
        <ModSettings>
            <MsPerTick>''' + str(TICK_LENGTH) + '''</MsPerTick>
        </ModSettings>

        <ServerSection>
            <ServerInitialConditions>
                <AllowSpawning>false</AllowSpawning>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                ''' + mazeblock + '''
                <ServerQuitFromTimeUp timeLimitMs="45000"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>James Bond</Name>
            <AgentStart>
                <Placement x="-204" y="81" z="217"/>
            </AgentStart>
            <AgentHandlers>
                <ContinuousMovementCommands turnSpeedDegs="840">
                    <ModifierList type="deny-list"> <!-- Example deny-list: prevent agent from strafing -->
                        <command>strafe</command>
                    </ModifierList>
                </ContinuousMovementCommands>''' + malmoutils.get_video_xml(agent_host) + '''
Exemple #3
0
def getMissionXML(summary):
    ''' Build an XML mission string.'''
    spawn_end_tag = ' type="mob_spawner" variant="' + MOB_TYPE + '"/>'
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>''' + summary + '''</Summary>
        </About>

        <ModSettings>
            <MsPerTick>20</MsPerTick>
        </ModSettings>
        <ServerSection>
            <ServerInitialConditions>
                <Time>
                    <StartTime>13000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <AllowSpawning>true</AllowSpawning>
                <AllowedMobs>''' + MOB_TYPE + '''</AllowedMobs>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid ''' + getCorner("1",True,True,expand=1) + " " + getCorner("2",False,False,y=226,expand=1) + ''' type="stone"/>
                    <DrawCuboid ''' + getCorner("1",True,True,y=207) + " " + getCorner("2",False,False,y=226) + ''' type="air"/>

                    <DrawLine ''' + getCorner("1",True,True) + " " + getCorner("2",True,False) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner("1",True,True) + " " + getCorner("2",False,True) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner("1",False,False) + " " + getCorner("2",True,False) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner("1",False,False) + " " + getCorner("2",False,True) + spawn_end_tag + '''
                    <DrawCuboid x1="-1" y1="206" z1="-1" x2="1" y2="206" z2="1" ''' + spawn_end_tag + '''
                    ''' + getItemXML() + '''
                </DrawingDecorator>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>The Hunted</Name>
            <AgentStart>
                <Placement x="0.5" y="207.0" z="0.5"/>
                <Inventory>
                </Inventory>
            </AgentStart>
            <AgentHandlers>
                <ChatCommands/>
                <ContinuousMovementCommands turnSpeedDegs="360"/>
                <AbsoluteMovementCommands/>
                <ObservationFromNearbyEntities>
                    <Range name="entities" xrange="'''+str(ARENA_WIDTH)+'''" yrange="2" zrange="'''+str(ARENA_BREADTH)+'''" />
                </ObservationFromNearbyEntities>
                <ObservationFromFullStats/>
                <RewardForCollectingItem>
                    <Item type="'''+GOAL_TYPE+'''" reward="'''+str(GOAL_REWARD)+'''"/>
                </RewardForCollectingItem>''' + malmoutils.get_video_xml(agent_host) + '''
            <AgentStart>
                <Placement x="0.5" y="56.0" z="0.5" pitch="18"/>
                <Inventory/>
            </AgentStart>
            <AgentHandlers>
                <ObservationFromFullInventory flat="false"/>
                <ObservationFromRay/>
                <InventoryCommands/>
                <ContinuousMovementCommands />
                <MissionQuitCommands />
                <RewardForCollectingItem>
                    <Item reward="-1" type="stained_glass"/>
                </RewardForCollectingItem>
                <RewardForDiscardingItem>
                    <Item reward="1" type="stained_glass"/>
                </RewardForDiscardingItem>''' + malmoutils.get_video_xml(
    agent_host) + '''
            </AgentHandlers>
        </AgentSection>

    </Mission>'''

my_mission = MalmoPython.MissionSpec(missionXML, True)
num_missions = 10 if agent_host.receivedArgument("test") else 30000
for mission_no in range(num_missions):
    merges_allowed = mission_no % 2
    my_mission_record = malmoutils.get_default_recording_object(
        agent_host, "Mission_{}".format(mission_no + 1))
    max_retries = 3
    for retry in range(max_retries):
        try:
            agent_host.startMission(my_mission, my_mission_record)
# By default, mods will choose consecutive mission control ports, starting at 10000,
# so running four mods locally should produce the following pool by default (assuming nothing else
# is using these ports):
my_client_pool = MalmoPython.ClientPool()
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10000))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10001))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10002))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10003))

if agent_host.receivedArgument("test"):
    num_reps = 1
else:
    num_reps = 30000

for iRepeat in range(num_reps):
    my_mission = MalmoPython.MissionSpec(GetMissionXML("Let them eat fish/cookies #" + str(iRepeat + 1), malmoutils.get_video_xml(agent_host)),validate)
    # Set up a recording
    my_mission_record = malmoutils.get_default_recording_object(agent_host, "Mission_{}".format(iRepeat + 1))
    max_retries = 3
    for retry in range(max_retries):
        try:
            # Attempt to start the mission:
            agent_host.startMission( my_mission, my_client_pool, my_mission_record, 0, "itemDiscardTestExperiment" )
            break
        except RuntimeError as e:
            if retry == max_retries - 1:
                print("Error starting mission",e)
                print("Is the game running?")
                exit(1)
            else:
                time.sleep(2)
Exemple #6
0
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------------------------
'''Tests malmoutils.'''

import MalmoPython
import malmoutils

agentHost = MalmoPython.AgentHost()

# See if we can parse our extended command line.
malmoutils.parse_command_line(agentHost)

# As we are not recording our video xml should be an empty string.
assert malmoutils.get_video_xml(agentHost) == ''

# Test that we can get a default recording spec.
assert type(malmoutils.get_default_recording_object(
    agentHost, "test")) == MalmoPython.MissionRecordSpec

# Default recordings directory is ''.
assert malmoutils.get_recordings_directory(agentHost) == ''


def clientInfos(cp):
    return [(c.ip_address, c.control_port, c.command_port) for c in cp.clients]


# Test adding some client infos to a client pool.
clientPool = MalmoPython.ClientPool()
Exemple #7
0
            <AgentStart>
                <Placement x="0.5" y="56.0" z="0.5" pitch="18"/>
                <Inventory/>
            </AgentStart>
            <AgentHandlers>
                <ObservationFromFullInventory flat="false"/>
                <ObservationFromRay/>
                <InventoryCommands/>
                <ContinuousMovementCommands />
                <MissionQuitCommands />
                <RewardForCollectingItem>
                    <Item reward="-1" type="stained_glass"/>
                </RewardForCollectingItem>
                <RewardForDiscardingItem>
                    <Item reward="1" type="stained_glass"/>
                </RewardForDiscardingItem>''' + malmoutils.get_video_xml(agent_host) + '''
            </AgentHandlers>
        </AgentSection>

    </Mission>'''

my_mission = MalmoPython.MissionSpec(missionXML,True)
num_missions = 10 if agent_host.receivedArgument("test") else 30000
for mission_no in range(num_missions):
    merges_allowed = mission_no % 2
    my_mission_record = malmoutils.get_default_recording_object(agent_host, "Mission_{}".format(mission_no + 1))
    max_retries = 3
    for retry in range(max_retries):
        try:
            agent_host.startMission( my_mission, my_mission_record )
            break
WAIT_TIME = agent_host.getFloatArgument("wait")
MISSION_LENGTH = 30
NUM_REPEATS = 10

if agent_host.receivedArgument("test"):
    print("Using test settings (overrides other command-line arguments).")
    NUM_REPEATS = 1
    WAIT_TIME = 0.2
    STOP = True
    PATH_LENGTH = 20
 
agent_host.setObservationsPolicy(MalmoPython.ObservationsPolicy.KEEP_ALL_OBSERVATIONS)
agent_host.setRewardsPolicy(MalmoPython.RewardsPolicy.KEEP_ALL_REWARDS)

for iRepeat in range(NUM_REPEATS):
    my_mission = MalmoPython.MissionSpec(GetMissionXML(iRepeat, malmoutils.get_video_xml(agent_host)), validate)
    # Set up a recording
    my_mission_record = malmoutils.get_default_recording_object(agent_host, "QuitFromReachingPosition_Test" + str(iRepeat));
    max_retries = 3
    for retry in range(max_retries):
        try:
            agent_host.startMission( my_mission, my_mission_record )
            break
        except RuntimeError as e:
            if retry == max_retries - 1:
                print("Error starting mission:",e)
                exit(1)
            else:
                time.sleep(2)

    world_state = agent_host.getWorldState()
def GetMissionXML(summary):
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>''' + summary + '''</Summary>
        </About>

        <ServerSection>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-50" y1="226" z1="-50" x2="50" y2="227" z2="50" type="lapis_block"/>
                </DrawingDecorator>
                <MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-50" y="226" z="-50"/>
                       <max x="50" y="226" z="50"/>
                    </ArenaBounds>
                    <StartPos x="3" y="226" z="0"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>turnbased</UpdateSpeed>
                    <PermeableBlocks type="air obsidian"/>
                    <BlockType type="glowstone"/>
                </MovingTargetDecorator>
                <MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-50" y="226" z="-50"/>
                       <max x="50" y="226" z="50"/>
                    </ArenaBounds>
                    <StartPos x="-3" y="226" z="0"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>1</UpdateSpeed>
                    <PermeableBlocks type="air obsidian"/>
                    <BlockType type="beacon"/>
                </MovingTargetDecorator>
                <MazeDecorator>
                    <SizeAndPosition length="20" width="20" yOrigin="226" zOrigin="-10" xOrigin="-10" height="20"/>
                    <GapProbability>0.1</GapProbability>
                    <Seed>random</Seed>
                    <MaterialSeed>random</MaterialSeed>
                    <AllowDiagonalMovement>false</AllowDiagonalMovement>
                    <StartBlock fixedToEdge="false" type="emerald_block" height="0"/>
                    <EndBlock fixedToEdge="false" type="redstone_block" height="0"/>
                    <PathBlock type="obsidian" height="0"/>
                    <FloorBlock type="obsidian"/>
                    <GapBlock type="stained_hardened_clay" height="1"/>
                </MazeDecorator>
                <ServerQuitFromTimeUp timeLimitMs="150000"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Creative">
            <Name>Chevy</Name>
            <AgentStart>
                <Placement x="0.5" y="227.0" z="0.5"/>
            </AgentStart>
            <AgentHandlers>
                <TurnBasedCommands requestedPosition="1">
                    <DiscreteMovementCommands/>
                </TurnBasedCommands>
                <AgentQuitFromTouchingBlockType>
                    <Block type="glowstone"/>
                </AgentQuitFromTouchingBlockType>''' + malmoutils.get_video_xml(
        agent_host) + '''
                  <ServerQuitFromTimeUp timeLimitMs="30000"/>
                  <ServerQuitWhenAnyAgentFinishes/>
                </ServerHandlers>
              </ServerSection>
              
              <AgentSection mode="Survival">
                <Name>QuitBot</Name>
                <AgentStart/>
                <AgentHandlers>
                  <ObservationFromFullStats/>
                  <ContinuousMovementCommands turnSpeedDegs="180"/>
                  <ChatCommands />
                  <MissionQuitCommands quitDescription="give_up"/>
                  <RewardForMissionEnd>
                    <Reward description="give_up" reward="-1000"/>
                  </RewardForMissionEnd>''' + malmoutils.get_video_xml(agent_host) + '''
                </AgentHandlers>
              </AgentSection>
            </Mission>'''

# Create default Malmo objects:

my_mission = MalmoPython.MissionSpec(missionXML, True)
my_mission_record = malmoutils.get_default_recording_object(agent_host, "Mission_1")

# Attempt to start a mission:
max_retries = 3
for retry in range(max_retries):
    try:
        agent_host.startMission( my_mission, my_mission_record )
        break
Exemple #11
0
import MalmoPython
import os
import random
import sys
import time
import json
import random
import errno
import malmoutils

malmoutils.fix_print()

agent_host = MalmoPython.AgentHost()
malmoutils.parse_command_line(agent_host)
recordingsDirectory = malmoutils.get_recordings_directory(agent_host)
video_requirements = malmoutils.get_video_xml(agent_host)


def getMissionXML():
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>Moving Times</Summary>
        </About>

        <ServerSection>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-21" y1="226" z1="-21" x2="21" y2="236" z2="21" type="air"/>
                    <DrawCuboid x1="-21" y1="226" z1="-21" x2="21" y2="226" z2="21" type="lava"/>
# is using these ports):
my_client_pool = MalmoPython.ClientPool()
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10000))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10001))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10002))
my_client_pool.add(MalmoPython.ClientInfo("127.0.0.1", 10003))

if agent_host.receivedArgument("test"):
    num_reps = 1
else:
    num_reps = 30000

for iRepeat in range(num_reps):
    my_mission = MalmoPython.MissionSpec(
        GetMissionXML("Let them eat fish/cookies #" + str(iRepeat + 1),
                      malmoutils.get_video_xml(agent_host)), validate)
    # Set up a recording
    my_mission_record = malmoutils.get_default_recording_object(
        agent_host, "Mission_{}".format(iRepeat + 1))
    max_retries = 3
    for retry in range(max_retries):
        try:
            # Attempt to start the mission:
            agent_host.startMission(my_mission, my_client_pool,
                                    my_mission_record, 0,
                                    "itemDiscardTestExperiment")
            break
        except RuntimeError as e:
            if retry == max_retries - 1:
                print("Error starting mission", e)
                print("Is the game running?")
Exemple #13
0
def GetMissionXML(summary):
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>''' + summary + '''</Summary>
        </About>

        <ServerSection>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-50" y1="226" z1="-50" x2="50" y2="227" z2="50" type="lapis_block"/>
                </DrawingDecorator>
                <MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-50" y="226" z="-50"/>
                       <max x="50" y="226" z="50"/>
                    </ArenaBounds>
                    <StartPos x="3" y="226" z="0"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>turnbased</UpdateSpeed>
                    <PermeableBlocks type="air obsidian"/>
                    <BlockType type="glowstone"/>
                </MovingTargetDecorator>
                <MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-50" y="226" z="-50"/>
                       <max x="50" y="226" z="50"/>
                    </ArenaBounds>
                    <StartPos x="-3" y="226" z="0"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>1</UpdateSpeed>
                    <PermeableBlocks type="air obsidian"/>
                    <BlockType type="beacon"/>
                </MovingTargetDecorator>
                <MazeDecorator>
                    <SizeAndPosition length="20" width="20" yOrigin="226" zOrigin="-10" xOrigin="-10" height="20"/>
                    <GapProbability>0.1</GapProbability>
                    <Seed>random</Seed>
                    <MaterialSeed>random</MaterialSeed>
                    <AllowDiagonalMovement>false</AllowDiagonalMovement>
                    <StartBlock fixedToEdge="false" type="emerald_block" height="0"/>
                    <EndBlock fixedToEdge="false" type="redstone_block" height="0"/>
                    <PathBlock type="obsidian" height="0"/>
                    <FloorBlock type="obsidian"/>
                    <GapBlock type="stained_hardened_clay" height="1"/>
                </MazeDecorator>
                <ServerQuitFromTimeUp timeLimitMs="150000"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Creative">
            <Name>Chevy</Name>
            <AgentStart>
                <Placement x="0.5" y="227.0" z="0.5"/>
            </AgentStart>
            <AgentHandlers>
                <TurnBasedCommands requestedPosition="1">
                    <DiscreteMovementCommands/>
                </TurnBasedCommands>
                <AgentQuitFromTouchingBlockType>
                    <Block type="glowstone"/>
                </AgentQuitFromTouchingBlockType>''' + malmoutils.get_video_xml(agent_host) + '''
Exemple #14
0
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ------------------------------------------------------------------------------------------------

'''Tests malmoutils.'''

import MalmoPython
import malmoutils

agentHost = MalmoPython.AgentHost()

# See if we can parse our extended command line.
malmoutils.parse_command_line(agentHost)

# As we are not recording our video xml should be an empty string.
assert malmoutils.get_video_xml(agentHost) == ''

# Test that we can get a default recording spec.
assert type(malmoutils.get_default_recording_object(agentHost, "test")) == MalmoPython.MissionRecordSpec

# Default recordings directory is ''.
assert malmoutils.get_recordings_directory(agentHost) == ''

def clientInfos(cp):
    return [(c.ip_address, c.control_port, c.command_port) for c in cp.clients]

# Test adding some client infos to a client pool.
clientPool = MalmoPython.ClientPool()
assert len(clientPool.clients) == 0
c1 = ("localhost", 10000, 0)
client1 = MalmoPython.ClientInfo(*c1)
def GetMissionXML( agent_host, seed, include_beacon ):
    beacon = '''<MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-1" y="226" z="-1"/>
                       <max x="40" y="226" z="40"/>
                    </ArenaBounds>
                    <StartPos x="10" y="226" z="40"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>1</UpdateSpeed>
                    <PermeableBlocks type="redstone_block emerald_block purpur_block"/>
                    <BlockType type="beacon"/>
                </MovingTargetDecorator>''' if include_beacon else ""

    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>Navigating via Mouse Commands</Summary>
        </About>

        <ServerSection>
            <ServerInitialConditions>
                <Time>
                    <StartTime>13000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <AllowSpawning>false</AllowSpawning>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-2" y1="225" z1="-2" x2="41" y2="225" z2="41" type="stone" variant="smooth_granite"/>
                    <DrawCuboid x1="-2" y1="226" z1="-2" x2="41" y2="226" z2="41" type="air"/>
                    <DrawCuboid x1="-1" y1="226" z1="-1" x2="40" y2="226" z2="40" type="purpur_block"/>
                </DrawingDecorator>
                <MazeDecorator>
                    <SizeAndPosition length="40" width="40" yOrigin="225" zOrigin="0" height="18"/>
                    <GapProbability variance="0.4">0.5</GapProbability>
                    <Seed>''' + seed + '''</Seed>
                    <MaterialSeed>random</MaterialSeed>
                    <AllowDiagonalMovement>false</AllowDiagonalMovement>
                    <StartBlock fixedToEdge="true" type="emerald_block" height="1"/>
                    <EndBlock fixedToEdge="true" type="redstone_block" height="12"/>
                    <PathBlock type="coal_block" height="1"/>
                    <FloorBlock type="stone" variant="smooth_granite"/>
                    <OptimalPathBlock type="purpur_block"/>
                    <GapBlock type="air"/>
                    <AddQuitProducer description="finished_maze"/>
                    <AddNavigationObservations/>
                </MazeDecorator>''' + beacon + '''
                <ServerQuitFromTimeUp timeLimitMs="450000" description="time_up"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>LittleMouse</Name>
            <AgentStart>
                <Placement x="-204" y="81" z="217"/>
            </AgentStart>
            <AgentHandlers>
                <HumanLevelCommands/>''' + malmoutils.get_video_xml(agent_host) + '''
NUM_REPEATS = 10

if agent_host.receivedArgument("test"):
    print("Using test settings (overrides other command-line arguments).")
    NUM_REPEATS = 1
    WAIT_TIME = 0.2
    STOP = True
    PATH_LENGTH = 20

agent_host.setObservationsPolicy(
    MalmoPython.ObservationsPolicy.KEEP_ALL_OBSERVATIONS)
agent_host.setRewardsPolicy(MalmoPython.RewardsPolicy.KEEP_ALL_REWARDS)

for iRepeat in range(NUM_REPEATS):
    my_mission = MalmoPython.MissionSpec(
        GetMissionXML(iRepeat, malmoutils.get_video_xml(agent_host)), validate)
    # Set up a recording
    my_mission_record = malmoutils.get_default_recording_object(
        agent_host, "QuitFromReachingPosition_Test" + str(iRepeat))
    max_retries = 3
    for retry in range(max_retries):
        try:
            agent_host.startMission(my_mission, my_mission_record)
            break
        except RuntimeError as e:
            if retry == max_retries - 1:
                print("Error starting mission:", e)
                exit(1)
            else:
                time.sleep(2)
                  <ServerQuitFromTimeUp timeLimitMs="30000"/>
                  <ServerQuitWhenAnyAgentFinishes/>
                </ServerHandlers>
              </ServerSection>
              
              <AgentSection mode="Survival">
                <Name>QuitBot</Name>
                <AgentStart/>
                <AgentHandlers>
                  <ObservationFromFullStats/>
                  <ContinuousMovementCommands turnSpeedDegs="180"/>
                  <ChatCommands />
                  <MissionQuitCommands quitDescription="give_up"/>
                  <RewardForMissionEnd>
                    <Reward description="give_up" reward="-1000"/>
                  </RewardForMissionEnd>''' + malmoutils.get_video_xml(
    agent_host) + '''
                </AgentHandlers>
              </AgentSection>
            </Mission>'''

# Create default Malmo objects:

my_mission = MalmoPython.MissionSpec(missionXML, True)
my_mission_record = malmoutils.get_default_recording_object(
    agent_host, "Mission_1")

# Attempt to start a mission:
max_retries = 3
for retry in range(max_retries):
    try:
        agent_host.startMission(my_mission, my_mission_record)
def GetMissionXML(agent_host, seed, include_beacon):
    beacon = '''<MovingTargetDecorator>
                    <ArenaBounds>
                       <min x="-1" y="226" z="-1"/>
                       <max x="40" y="226" z="40"/>
                    </ArenaBounds>
                    <StartPos x="10" y="226" z="40"/>
                    <Seed>random</Seed>
                    <UpdateSpeed>1</UpdateSpeed>
                    <PermeableBlocks type="redstone_block emerald_block purpur_block"/>
                    <BlockType type="beacon"/>
                </MovingTargetDecorator>''' if include_beacon else ""

    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>Navigating via Mouse Commands</Summary>
        </About>

        <ServerSection>
            <ServerInitialConditions>
                <Time>
                    <StartTime>13000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <AllowSpawning>false</AllowSpawning>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-2" y1="225" z1="-2" x2="41" y2="225" z2="41" type="stone" variant="smooth_granite"/>
                    <DrawCuboid x1="-2" y1="226" z1="-2" x2="41" y2="226" z2="41" type="air"/>
                    <DrawCuboid x1="-1" y1="226" z1="-1" x2="40" y2="226" z2="40" type="purpur_block"/>
                </DrawingDecorator>
                <MazeDecorator>
                    <SizeAndPosition length="40" width="40" yOrigin="225" zOrigin="0" height="18"/>
                    <GapProbability variance="0.4">0.5</GapProbability>
                    <Seed>''' + seed + '''</Seed>
                    <MaterialSeed>random</MaterialSeed>
                    <AllowDiagonalMovement>false</AllowDiagonalMovement>
                    <StartBlock fixedToEdge="true" type="emerald_block" height="1"/>
                    <EndBlock fixedToEdge="true" type="redstone_block" height="12"/>
                    <PathBlock type="coal_block" height="1"/>
                    <FloorBlock type="stone" variant="smooth_granite"/>
                    <OptimalPathBlock type="purpur_block"/>
                    <GapBlock type="air"/>
                    <AddQuitProducer description="finished_maze"/>
                    <AddNavigationObservations/>
                </MazeDecorator>''' + beacon + '''
                <ServerQuitFromTimeUp timeLimitMs="450000" description="time_up"/>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>LittleMouse</Name>
            <AgentStart>
                <Placement x="-204" y="81" z="217"/>
            </AgentStart>
            <AgentHandlers>
                <HumanLevelCommands/>''' + malmoutils.get_video_xml(
        agent_host) + '''
Exemple #19
0
def getMissionXML(summary):
    ''' Build an XML mission string.'''
    spawn_end_tag = ' type="mob_spawner" variant="' + MOB_TYPE + '"/>'
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>''' + summary + '''</Summary>
        </About>

        <ModSettings>
            <MsPerTick>20</MsPerTick>
        </ModSettings>
        <ServerSection>
            <ServerInitialConditions>
                <Time>
                    <StartTime>13000</StartTime>
                    <AllowPassageOfTime>false</AllowPassageOfTime>
                </Time>
                <AllowSpawning>true</AllowSpawning>
                <AllowedMobs>''' + MOB_TYPE + '''</AllowedMobs>
            </ServerInitialConditions>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid ''' + getCorner(
        "1", True, True, expand=1) + " " + getCorner(
            "2", False, False, y=226, expand=1) + ''' type="stone"/>
                    <DrawCuboid ''' + getCorner(
                "1", True, True, y=207
            ) + " " + getCorner("2", False, False, y=226) + ''' type="air"/>

                    <DrawLine ''' + getCorner(
                "1", True,
                True) + " " + getCorner("2", True, False) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner(
                    "1", True, True) + " " + getCorner(
                        "2", False, True) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner(
                            "1", False, False) + " " + getCorner(
                                "2", True, False) + spawn_end_tag + '''
                    <DrawLine ''' + getCorner(
                                    "1", False, False) + " " + getCorner(
                                        "2", False, True) + spawn_end_tag + '''
                    <DrawCuboid x1="-1" y1="206" z1="-1" x2="1" y2="206" z2="1" ''' + spawn_end_tag + '''
                    ''' + getItemXML() + '''
                </DrawingDecorator>
                <ServerQuitWhenAnyAgentFinishes />
            </ServerHandlers>
        </ServerSection>

        <AgentSection mode="Survival">
            <Name>The Hunted</Name>
            <AgentStart>
                <Placement x="0.5" y="207.0" z="0.5"/>
                <Inventory>
                </Inventory>
            </AgentStart>
            <AgentHandlers>
                <ChatCommands/>
                <ContinuousMovementCommands turnSpeedDegs="360"/>
                <AbsoluteMovementCommands/>
                <ObservationFromNearbyEntities>
                    <Range name="entities" xrange="''' + str(
                                            ARENA_WIDTH
                                        ) + '''" yrange="2" zrange="''' + str(
                                            ARENA_BREADTH) + '''" />
                </ObservationFromNearbyEntities>
                <ObservationFromFullStats/>
                <RewardForCollectingItem>
                    <Item type="''' + GOAL_TYPE + '''" reward="''' + str(
                                                GOAL_REWARD) + '''"/>
                </RewardForCollectingItem>''' + malmoutils.get_video_xml(
                                                    agent_host) + '''
Exemple #20
0
import MalmoPython
import os
import random
import sys
import time
import json
import random
import errno
import malmoutils

malmoutils.fix_print()

agent_host = MalmoPython.AgentHost()
malmoutils.parse_command_line(agent_host)
recordingsDirectory = malmoutils.get_recordings_directory(agent_host)
video_requirements = malmoutils.get_video_xml(agent_host)
    
def getMissionXML():
    return '''<?xml version="1.0" encoding="UTF-8" ?>
    <Mission xmlns="http://ProjectMalmo.microsoft.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
        <About>
            <Summary>Moving Times</Summary>
        </About>

        <ServerSection>
            <ServerHandlers>
                <FlatWorldGenerator generatorString="3;7,220*1,5*3,2;3;,biome_1" />
                <DrawingDecorator>
                    <DrawCuboid x1="-21" y1="226" z1="-21" x2="21" y2="236" z2="21" type="air"/>
                    <DrawCuboid x1="-21" y1="226" z1="-21" x2="21" y2="226" z2="21" type="lava"/>
                    <DrawCuboid x1="-20" y1="226" z1="-20" x2="20" y2="16" z2="20" type="gold_block" />