def test_record_quest_from_commands(play_the_game=False): M = GameMaker() # The goal commands = ["go east", "insert ball into chest"] # Create a 'bedroom' room. R1 = M.new_room("bedroom") R2 = M.new_room("kitchen") M.set_player(R1) path = M.connect(R1.east, R2.west) path.door = M.new(type='d', name='wooden door') path.door.add_property("open") ball = M.new(type='o', name='ball') M.inventory.add(ball) # Add a closed chest in R2. chest = M.new(type='c', name='chest') chest.add_property("open") R2.add(chest) M.set_quest_from_commands(commands) game = M.build() with make_temp_directory( prefix="test_record_quest_from_commands") as tmpdir: game_file = _compile_game(game, folder=tmpdir) if play_the_game: textworld.play(game_file) else: agent = textworld.agents.WalkthroughAgent(commands) textworld.play(game_file, agent=agent, silent=True)
def build_test_game(): M = GameMaker() # The goal commands = ["go east", "insert carrot into chest"] # Create a 'bedroom' room. R1 = M.new_room("bedroom") R2 = M.new_room("kitchen") M.set_player(R1) path = M.connect(R1.east, R2.west) path.door = M.new(type='d', name='wooden door') path.door.add_property("open") carrot = M.new(type='f', name='carrot') M.inventory.add(carrot) # Add a closed chest in R2. chest = M.new(type='c', name='chest') chest.add_property("open") R2.add(chest) M.set_quest_from_commands(commands) game = M.build() return game