Пример #1
0
def start_mission():
    miss = mb.MissionXML()
    colourmap_producer = mb.ColourMapProducer(width=WIDTH, height=HEIGHT)
    video_producer = mb.VideoProducer(width=WIDTH, height=HEIGHT, want_depth=False)
    colourmap_producer = None

    obs = mb.Observations()
    agent_handlers = mb.AgentHandlers(observations=obs)

    agent_handlers = mb.AgentHandlers(observations=obs,
        colourmap_producer=colourmap_producer,
        video_producer=video_producer)

    miss = mb.MissionXML(agentSections=[mb.AgentSection(name='Cristina',
             agenthandlers=agent_handlers)])
    
    # seed 28 - with a see
    world = mb.defaultworld(
        seed='28',
        forceReset="false")

    
    miss.setWorld(world)
    miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    # disable passage of time:
    miss.serverSection.initial_conditions.time_pass = '******'
    miss.serverSection.initial_conditions.time_start = "1000"

    mc = MalmoConnector(miss)
    obs1 = RobustObserverWithCallbacks(mc)
    return mc, obs1
Пример #2
0
    def init_mission(cls, i, mc):
        miss = mb.MissionXML()
        video_producer = mb.VideoProducer(width=320, height=240, want_depth=cls.want_depth)

        obs = mb.Observations()
        agent_handlers = mb.AgentHandlers(observations=obs,
            all_str=mission_ending, video_producer=video_producer)
        # a tree is at -18, 15
        # stay between tree and pond
        center_x = -23.5
        center_y = 12.5
        start_x = center_x + random.choice(numpy.arange(-2, 2))
        start_y = center_y + random.choice(numpy.arange(-5, 5))

        logging.info('starting at ({0}, {1})'.format(start_x, start_y))
        miss = mb.MissionXML(agentSections=[mb.AgentSection(name='Cristina',
                 agenthandlers=agent_handlers,
                                          #    depth
                 agentstart=mb.AgentStart([start_x, 30.0, start_y, 1]))])

        miss.setWorld(mb.flatworld("3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake",
            seed='43',
            forceReset="false"))
        miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"

        if mc is None:
            mc = MalmoConnector(miss)
        else:
            mc.setMissionXML(miss)
        return mc
Пример #3
0
def init_mission(mc,
                 start_x=None,
                 start_y=None,
                 use_video=False,
                 use_colormap=False):
    miss = mb.MissionXML()
    colourmap_producer = None
    if use_colormap:
        colourmap_producer = mb.ColourMapProducer(width=320 * 4,
                                                  height=240 * 4)
    video_producer = None
    if use_video:
        video_producer = mb.VideoProducer(width=320 * 4,
                                          height=240 * 4,
                                          want_depth=False)

    obs = mb.Observations()
    obs.gridNear = [[-1, 1], [-2, 1], [-1, 1]]

    agent_handlers = mb.AgentHandlers(observations=obs, all_str=mission_ending)

    agent_handlers = mb.AgentHandlers(observations=obs,
                                      all_str=mission_ending,
                                      colourmap_producer=colourmap_producer,
                                      video_producer=video_producer)
    # a tree is at -18, 15
    if start_x is None:
        center_x = -18
        center_y = 15

        start_x = center_x + random.choice(numpy.arange(-329, 329))
        start_y = center_y + random.choice(numpy.arange(-329, 329))

    logging.info('starting at ({0}, {1})'.format(start_x, start_y))

    miss = mb.MissionXML(agentSections=[
        mb.AgentSection(
            name='Cristina',
            agenthandlers=agent_handlers,  #)])
            #    depth
            agentstart=mb.AgentStart([start_x, 30.0, start_y, 1]))
    ])
    world = mb.flatworld(
        "3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake",
        seed='43',
        forceReset="false")
    miss.setWorld(world)
    miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    # uncomment to disable passage of time:
    miss.serverSection.initial_conditions.time_pass = '******'
    miss.serverSection.initial_conditions.time_start = "1000"

    if mc is None:
        mc = MalmoConnector(miss)
    else:
        mc.setMissionXML(miss)
    obs1 = RobustObserver(mc)
    return mc, obs1
Пример #4
0
def init_mission(mc, start_x=None, start_y=None):
    want_depth = False
    video_producer = mb.VideoProducer(width=320 * 4,
                                      height=240 * 4,
                                      want_depth=want_depth)

    obs = mb.Observations()
    obs.gridNear = [[-1, 1], [-2, 1], [-1, 1]]

    agent_handlers = mb.AgentHandlers(observations=obs,
                                      video_producer=video_producer)

    print('starting at ({0}, {1})'.format(start_x, start_y))

    #miss = mb.MissionXML(namespace="ProjectMalmo.microsoft.com",
    miss = mb.MissionXML(agentSections=[
        mb.AgentSection(
            name='Cristina',
            agenthandlers=agent_handlers,
            #    depth
            agentstart=mb.AgentStart([start_x, 74.0, start_y, 1]))
    ])
    flat_json = {
        "biome": "minecraft:plains",
        "layers": [{
            "block": "minecraft:diamond_block",
            "height": 1
        }],
        "structures": {
            "structures": {
                "village": {}
            }
        }
    }

    flat_param = "3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake"
    flat_json = json.dumps(flat_json).replace('"', "%ESC")
    world = mb.defaultworld(seed='5', forceReuse="true", forceReset="false")
    flat_world = mb.flatworld(
        flat_json,
        seed='43',
    )
    miss.setWorld(world)
    miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    # uncomment to disable passage of time:
    miss.serverSection.initial_conditions.time_pass = '******'
    miss.serverSection.initial_conditions.time_start = "1000"

    if mc is None:
        mc = MalmoConnector(miss)
        obs = RobustObserver(mc)
    else:
        mc.setMissionXML(miss)
    return mc, obs
Пример #5
0
def start_mission():
    miss = mb.MissionXML()
    colourmap_producer = mb.ColourMapProducer(width=WIDTH, height=HEIGHT)
    video_producer = mb.VideoProducer(width=WIDTH,
                                      height=HEIGHT,
                                      want_depth=False)

    obs = mb.Observations()
    agent_handlers = mb.AgentHandlers(observations=obs)

    agent_handlers = mb.AgentHandlers(observations=obs,
                                      colourmap_producer=colourmap_producer,
                                      video_producer=video_producer)

    miss = mb.MissionXML(agentSections=[
        mb.AgentSection(
            name='Cristina',
            agenthandlers=agent_handlers,
        )
    ])
    # agenthandlers=agent_handlers,)], namespace='ProjectMalmo.microsoft.com')

    # good point seed='2', x=-90, y=71, z=375
    # good point seed='3', x=6, y=71, z=350
    # good point seed='31'
    world = mb.defaultworld(seed='5', forceReset="true")

    world1 = mb.flatworld(
        "3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake",
        seed='43',
        forceReset="false")
    miss.setWorld(world)
    miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    # uncomment to disable passage of time:
    miss.serverSection.initial_conditions.time_pass = '******'
    miss.serverSection.initial_conditions.time_start = "1000"
    mc = MalmoConnector(miss)
    obs1 = RobustObserver(mc)
    return mc, obs1
Пример #6
0
    def init_mission(i, mc):
        sp = ''
        # train on simple environment first
        if i < 200:
            p = random.choice([x for x in range(2, 8)])
        else:
            p = random.choice([-2, -1] + [x for x in range(0, 12)])
            if random.choice([True, False]):
                sp = spiral
        jump_block = -3
        jump_block1 = random.choice(list(range(2, 11)))
        logging.debug('%i, %i', jump_block, jump_block1)
        current_xml = dec_xml.format(
            modify_blocks.format(p, jump_block, jump_block1), sp)
        handlers = mb.ServerHandlers(
            mb.flatworld("3;7,220*1,5*3,2;3;,biome_1"),
            alldecorators_xml=current_xml,
            bQuitAnyAgent=True)
        video_producer = mb.VideoProducer(width=320, height=240)

        obs = mb.Observations()
        obs.gridNear = [[-1, 1], [-2, 2], [-1, 1]]

        agent_handlers = mb.AgentHandlers(observations=obs,
                                          all_str=mission_ending)

        miss = mb.MissionXML(serverSection=mb.ServerSection(handlers),
                             agentSections=[
                                 mb.AgentSection(name='Cristina',
                                                 agenthandlers=agent_handlers,
                                                 agentstart=mb.AgentStart(
                                                     [4.5, 46.0, 1.5, 30]))
                             ])
        if mc is None:
            mc = MalmoConnector(miss)
        else:
            mc.setMissionXML(miss)
        return mc
        if iron_ore != None and iron_ore != [] and iron_ore[0]['quantity'] >= 3 and \
                coal != None and coal != [] and coal[0]['quantity'] >= 3:
            mc.sendCommand('craft iron_ingot')
            mc.sendCommand('craft iron_ingot')
            mc.sendCommand('craft iron_ingot')
            mc.sendCommand('craft iron_pickaxe')
            break
        pickaxe = mc.filterInventoryItem('stone_pickaxe')
        if mc.isInventoryAvailable() and pickaxe == []:
            break


video_producer = mb.VideoProducer(width=320, height=240)
agent_handler = mb.AgentHandlers(video_producer=video_producer)
agent_section = mb.AgentSection(agenthandlers=agent_handler)
miss = mb.MissionXML(agentSections=[agent_section])
miss.setWorld(
    mb.flatworld(
        "3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake",
        forceReset="true"))
miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
mc = MalmoConnector(miss)
mc.safeStart()
# fixing bug with falling through while reconnecting
sleep(2)
mc.sendCommand("jump 1")
sleep(0.1)
mc.sendCommand("jump 0")

lookDir(mc, 0, 0)
Пример #8
0
           coal != None and coal != [] and coal[0]['quantity'] >= 3:
            rob.craft('iron_ingot')
            rob.craft('iron_ingot')
            rob.craft('iron_ingot')
            rob.craft('iron_pickaxe')
            break
        pickaxe = rob.filterInventoryItem('stone_pickaxe')
        if pickaxe == []:
            break


if __name__ == '__main__':

    logging.basicConfig(level=logging.INFO)
    logging.info("Starting the mission")
    miss = mb.MissionXML()
    miss.setWorld(
        mb.flatworld(
            "3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake",
            forceReset="true"))
    miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    mc = MalmoConnector(miss)
    mc.safeStart()
    rob = RobustObserver(mc)
    # fixing bug with falling through while reconnecting
    logging.info("Initializing the starting position")
    sleep(2)
    rob.sendCommand("jump 1")
    sleep(0.1)
    rob.sendCommand("jump 0")
    lookDir(rob, 0, 0)
Пример #9
0
        for act in acts:
            self.rob.sendCommand(act)


if __name__ == '__main__':
    SCALE = 3
    setup_logger()
    visualizer = Visualizer()
    visualizer.start()
    video_producer = mb.VideoProducer(width=320 * SCALE,
                                      height=240 * SCALE,
                                      want_depth=False)
    agent_handlers = mb.AgentHandlers(video_producer=video_producer)
    miss = mb.MissionXML(agentSections=[
        mb.AgentSection(
            name='Robo',
            agenthandlers=agent_handlers,
        )
    ])

    world = mb.defaultworld(forceReset="true", seed="151")
    #113 122 127? 128 129+? 130+? 131+?
    miss.setWorld(world)

    agent = Explorer(miss, visualizer=visualizer)
    sleep(4)
    agent.run()
    '''
    rob = agent.rob
    skb = StaticKnowledge(rob)
    for i in range(600):
        sleep(0.2)
Пример #10
0
    formatter = logging.Formatter('%(asctime)s: %(levelname)-8s %(message)s')
    # create console handler and set level to debug
    ch = logging.StreamHandler()
    ch.setFormatter(formatter)
    ch.setLevel(logging.DEBUG)
    # add ch to logger
    logger.addHandler(ch)


if __name__ == '__main__':
    setup_logger()
    visualizer = Visualizer()
    visualizer.start()
    video_producer = mb.VideoProducer(width=320 * SCALE, height=240 * SCALE, want_depth=False)
    agent_handlers = mb.AgentHandlers(video_producer=video_producer)
    miss = mb.MissionXML(agentSections=[mb.AgentSection(name='Cristina',
             agenthandlers=agent_handlers,)])


    world = mb.flatworld("3;7,25*1,3*3,2;1;stronghold,biome_1,village,decoration,dungeon,lake,mineshaft,lava_lake", seed='43', forceReset="false")
    miss.serverSection.initial_conditions.time_pass = '******'
    miss.serverSection.initial_conditions.time_start = "1000"
    world1 = mb.defaultworld(forceReset="true")
    miss.setWorld(world1)
    # miss.serverSection.initial_conditions.allowedmobs = "Pig Sheep Cow Chicken Ozelot Rabbit Villager"
    agent = LJAgent(miss, visualizer=visualizer)
    agent.rob.sendCommand("chat /difficulty peaceful")
    # agent.loop()
    agent.loop(target = {'type': 'wooden_pickaxe'})

    visualizer.stop()
Пример #11
0
import tagilmo.utils.mission_builder as mb

# we can specify separate parameters through nested constructors
miss = mb.MissionXML(serverSection=mb.ServerSection(
    initial_conditions=mb.ServerInitialConditions(weather_string="rain")))

# we can use a nicer API, though
miss.setWorld(mb.flatworld(""))
miss.addAgent()
miss.setObservations(
    mb.Observations(bAll=False, bRay=True, bFullStats=True, bHotBar=True))

# we can also set some parameters this way if they are lacking API
miss.agentSections[0].agentstart.inventory = ["diamond_pickaxe", "wooden_axe"]

print(miss.xml())
print("================\n")
print(miss.getAgentNames())