def bootstrap_human(): agent_host = bootstrap_specific(world_file, clients, 1) agent = MalmoAgent.build(agent_host) time.sleep(3) agent.speak(SpeechTMR.build("Go to the grocery store."), join=True) time.sleep(14) agent.speak(SpeechTMR.build("Actually, go to the pharmacy first."), join=True) while agent.host().getWorldState().is_mission_running: time.sleep(2)
def run(self, agent: CLAgent, signal: ChatTMR): text = signal.raw_text() if "Ozymandias" in text: agent.speak(SpeechTMR.build( "Nothing beside remains. Round the decay Of that colossal wreck, boundless and bare The lone and level sands stretch far away." ), join=True) elif True in list( map(lambda c: c in text.lower(), ["move", "walk", "turn", "go"])): self.parse_command(agent, text) else: agent.speak(SpeechTMR.build("I heard %s say '%s'." % (signal.agent().id, text)), join=True)
def bootstrap_sasha(): agent_host = bootstrap_specific( ("tests.resources", "multiexample.xml"), clients, 0) agent = MalmoAgent.build(agent_host) action = False while agent.host().getWorldState().is_mission_running: time.sleep(2) if not action: tmr = SpeechTMR.build("Hello world.") agent.speak(tmr, join=True) action = True
def bootstrap_sasha(): agent_host = bootstrap_specific(("tests.resources", "25world.xml"), clients, 0) agent = CLAgent.build(agent_host, None) action = False time.sleep(1) while user.host().getWorldState().is_mission_running: time.sleep(1) if not action: tmr = SpeechTMR.build( "My name is Ozymandias, king of agents: Look on my works, ye Mighty, and despair!" ) user.speak(tmr, join=True) action = True user.observe(join=True)
if __name__ == "__main__": # Connect to the host host = bootstrap(("tests.resources", "example.xml")) host.sendCommand("hotbar.9 1") time.sleep(0.5) # Build a new agent agent = MalmoAgent.build(host) print(agent.anchor["HAS-NAME"].singleton()) # Observe location and surroundings agent.observe(join=True) # Say something tmr = SpeechTMR.build("Hello world.") agent.speak(tmr, join=True) # Construct a movement AMR path, and output it amr = MoveAMR.build() amr.add_to_path_turn_clockwise() amr.add_to_path_move_forward() amr.add_to_path_turn_counterclockwise() amr.add_to_path_move_forward() amr.add_to_path_move_forward() amr.add_to_path_move_forward() amr.add_to_path_move_forward() amr.add_to_path_move_forward() agent.move(amr, join=True)
def speaksentence(self, string: str): tmr = SpeechTMR.build(string) self.speak(tmr, join=True)
def parse_command(agent: CLAgent, signal: str): command = signal.lower() tmr = None path = None def _get_digits(text): return ''.join(filter(lambda x: x.isdigit(), text)) if True in list(map(lambda c: c in command, ["move", "walk", "go"])): agent.observe(join=True) facing = agent.facing() digit = _get_digits(command) digit = "1" if digit == "" else digit digit = int(digit) if "forward" in command: direction = 'fx1' # digit = "1" if digit == "" else digit # path = "fx" + digit tmr = SpeechTMR.build("Moving forward {} step{}".format( digit, "s" if int(digit) > 1 else "")) if "backward" in command: # digit = _get_digits(command) # digit = "1" if digit == "" else digit # path = "bx" + digit tmr = SpeechTMR.build("Moving backward {} step{}".format( digit, "s" if int(digit) > 1 else "")) direction = 'bx1' for i in range(digit): road = "" clear_road = False if (facing == PositionXMR.Facing.SOUTH): # the next block to walk on road = agent.environment().relative_block(agent, 0, -1, 1).type() # whether is the front road is blocked clear_road = (agent.environment().relative_block( agent, 0, 0, 1).type() == "") elif (facing == PositionXMR.Facing.WEST): road = agent.environment().relative_block(agent, 1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, 1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.EAST): road = agent.environment().relative_block( agent, -1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, 1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.NORTH): road = agent.environment().relative_block( agent, 0, -1, -1).type() clear_road = (agent.environment().relative_block( agent, 0, 0, -1).type() == "") if (road == "stone" and clear_road): agent.movepath(direction) else: tmr = SpeechTMR.build( "I cannot move this way, it is not a valid path") agent.speak(tmr, join=True) if True in list(map(lambda c: c in command, ["turn", "look"])): if True in list( map(lambda c: c in command, ["right", "clockwise", "cw"])): print('tr') digit = _get_digits(command) digit = "1" if digit == "" else digit path = "cwx" + digit print(digit) tmr = SpeechTMR.build("Turning clockwise {} step{}".format( digit, "s" if int(digit) > 1 else "")) if True in list( map(lambda c: c in command, ["left", "counterclockwise", "ccw"])): digit = _get_digits(command) digit = "1" if digit == "" else digit path = "ccwx" + digit tmr = SpeechTMR.build( "Turning counter-clockwise {} step{}".format( digit, "s" if int(digit) > 1 else "")) if tmr is not None: agent.speak(tmr) if path is not None: agent.movepath(path)
def follow_command(): fwd = False while (True): if (not fwd): s = input() facing = agent.facing() agent.observe(join=True) if (s == "keep moving forward"): fwd = True if (s == "stop"): fwd = False if (s == "move forward" or fwd): # print(facing) road = "" clear_road = False if (facing == PositionXMR.Facing.SOUTH): # the next block to walk on road = agent.environment().relative_block(agent, 0, -1, 1).type() # whether is the front road is blocked clear_road = (agent.environment().relative_block( agent, 0, 0, 1).type() == "") elif (facing == PositionXMR.Facing.WEST): road = agent.environment().relative_block(agent, 1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, 1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.EAST): road = agent.environment().relative_block(agent, -1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, 1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.NORTH): road = agent.environment().relative_block(agent, 0, -1, -1).type() clear_road = (agent.environment().relative_block( agent, 0, 0, -1).type() == "") if (road == "stone" and clear_road): agent.movepath('fx1') else: tmr = SpeechTMR.build( "I cannot move this way, it is not a valid path") agent.speak(tmr, join=True) fwd = False elif (s == "turn right"): agent.movepath('cwx1') elif (s == "turn left"): agent.movepath('ccwx1') elif (s == "back up"): if (facing == PositionXMR.Facing.SOUTH): # the next block to walk on road = agent.environment().relative_block(agent, 0, -1, -1).type() # whether is the front road is blocked clear_road = (agent.environment().relative_block( agent, 0, 0, -1).type() == "") elif (facing == PositionXMR.Facing.WEST): road = agent.environment().relative_block(agent, -1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, -1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.EAST): road = agent.environment().relative_block(agent, 1, -1, 0).type() clear_road = (agent.environment().relative_block( agent, 1, 0, 0).type() == "") elif (facing == PositionXMR.Facing.NORTH): road = agent.environment().relative_block(agent, 0, -1, 1).type() clear_road = (agent.environment().relative_block( agent, 0, 0, 1).type() == "") if (road == "stone" and clear_road): agent.movepath('bx1') else: tmr = SpeechTMR.build( "I cannot move this way, it is not a valid path") agent.speak(tmr, join=True) elif (s == 'turn around'): agent.movepath('cwx2')
if (road == "stone" and clear_road): agent.movepath('bx1') else: tmr = SpeechTMR.build( "I cannot move this way, it is not a valid path") agent.speak(tmr, join=True) elif (s == 'turn around'): agent.movepath('cwx2') if __name__ == '__main__': host = bootstrap(("worldtest.resources", "world.xml")) host.sendCommand("hotbar.9 1") time.sleep(0.5) # Build a new agent agent = CLAgent.build(host, None) print(agent.anchor["HAS-NAME"].singleton()) # Observe location and surroundings agent.observe(join=True) # After the user communicates to the agent that they want to visit the pharmacy, the agent # communicates to the user the decision that was made before planning a new route. tmr = SpeechTMR.build( "OK, I will go to the pharmacy, and then go to the grocery store.") agent.speak(tmr, join=True) follow_command()