def specs(self) -> Dict: return { "forward": spaces.Discrete(2), "jump": spaces.Discrete(2), "camera_pitch": spaces.Discrete(self._num_camera_actions), "camera_yaw": spaces.Discrete(self._num_camera_actions), "place": obtain_action_space["place"], "equip": obtain_action_space["equip"], "craft": obtain_action_space["craft"], "nearbyCraft": obtain_action_space["nearbyCraft"], "nearbySmelt": obtain_action_space["nearbySmelt"] }
register( id='MineRLTreechop-v0', entry_point='minerl.env:MineRLEnv', kwargs={ 'xml': os.path.join(missions_dir, 'treechop.xml'), 'observation_space': spaces.Dict({ 'pov': spaces.Box(low=0, high=255, shape=(64, 64, 3), dtype=np.uint8), }), 'action_space': spaces.Dict({ "forward": spaces.Discrete(2), "back": spaces.Discrete(2), "left": spaces.Discrete(2), "right": spaces.Discrete(2), "jump": spaces.Discrete(2), "sneak": spaces.Discrete(2), "sprint": spaces.Discrete(2), "attack": spaces.Discrete(2), "camera":
def register(environment_id, xml_path): """ Given an xml_path and a desired environment_id, registers the Minecraft mission as a gym environment. The environment_id is a string which you "register" here and then call later when doing gym.make(environment_id). The xml_path is the path to the Malmo mission file, which is in xml file format, of course. """ ENVIRONMENT_ID = environment_id XML_PATH = xml_path def make_navigate_text(top, dense): """ Helper function to construct the description for this gym environment. TODO: Copied as an example and needs to be removed / changed """ navigate_text = """ .. image:: ../assets/navigate{}1.mp4.gif :scale: 100 % :alt: .. image:: ../assets/navigate{}2.mp4.gif :scale: 100 % :alt: .. image:: ../assets/navigate{}3.mp4.gif :scale: 100 % :alt: .. image:: ../assets/navigate{}4.mp4.gif :scale: 100 % :alt: In this task, the agent must move to a goal location denoted by a diamond block. This represents a basic primitive used in many tasks throughout Minecraft. In addition to standard observations, the agent has access to a “compass” observation, which points near the goal location, 64 meters from the start location. The goal has a small random horizontal offset from the compass location and may be slightly below surface level. On the goal location is a unique block, so the agent must find the final goal by searching based on local visual features. The agent is given a sparse reward (+100 upon reaching the goal, at which point the episode terminates). """ if dense: navigate_text += "**This variant of the environment is dense reward-shaped where the agent is given a reward every tick for how much closer (or negative reward for farther) the agent gets to the target.**\n" else: navigate_text += "**This variant of the environment is sparse.**\n" if top is "normal": navigate_text += "\nIn this environment, the agent spawns on a random survival map.\n" navigate_text = navigate_text.format(*["" for _ in range(4)]) else: navigate_text += "\nIn this environment, the agent spawns in an extreme hills biome.\n" navigate_text = navigate_text.format( *["extreme" for _ in range(4)]) return navigate_text # Define the action space navigate_action_space = spaces.Dict({ "forward": spaces.Discrete(2), "back": spaces.Discrete(2), "left": spaces.Discrete(2), "right": spaces.Discrete(2), "jump": spaces.Discrete(2), # "sneak": spaces.Discrete(2), # "sprint": spaces.Discrete(2), # "attack": spaces.Discrete(2), "camera": spaces.Box(low=-180, high=180, shape=(2, ), dtype=np.float32), "place": spaces.Enum('none', 'dirt') }) # Define the information that the agent receives, and navigates using navigate_observation_space = spaces.Dict({ 'pov': spaces.Box(low=0, high=255, shape=(64, 64, 3), dtype=np.uint8), 'inventory': spaces.Dict( spaces={ 'dirt': spaces.Box(low=0, high=2304, shape=(), dtype=np.int) }), 'compassAngle': spaces.Box(low=-180.0, high=180.0, shape=(), dtype=np.float32) }) # This is the function call where we actually register # the environment gym.envs.registration.register( id=ENVIRONMENT_ID, entry_point='minerl.env:MineRLEnv', kwargs={ 'xml': XML_PATH, 'observation_space': navigate_observation_space, 'action_space': navigate_action_space, 'docstr': make_navigate_text('normal', False) }, max_episode_steps=6000, )
import numpy as np missions_dir = os.path.join(os.path.dirname(__file__), 'missions') register( id='MineRLWoolGatheringTrain-v0', entry_point='minerl.env:MineRLEnv', kwargs={ 'xml': os.path.join(missions_dir, 'wool_gather_train.xml'), 'observation_space': spaces.Dict({ 'pov': spaces.Box(low=0, high=255, shape=(64, 64, 3), dtype=np.uint8), }), 'action_space': spaces.Dict(spaces={ "forward": spaces.Discrete(2), "back": spaces.Discrete(2), "left": spaces.Discrete(2), "right": spaces.Discrete(2), "jump": spaces.Discrete(2), "sneak": spaces.Discrete(2), "sprint": spaces.Discrete(2), "attack": spaces.Discrete(2), "camera": spaces.Box(low=-180, high=180, shape=(2,), dtype=np.float32), }), }, max_episode_steps=8000, reward_threshold=1000.0, ) register(
def __init__(self): self.state = { 'equipped_items': { 'mainhand': { 'damage': 0, 'maxDamage': 0, 'type': 0 } }, 'inventory': { 'coal': 0, 'cobblestone': 0, 'crafting_table': 0, 'dirt': 0, 'furnace': 0, 'iron_axe': 0, 'iron_ingot': 0, 'iron_ore': 0, 'iron_pickaxe': 0, 'log': 0, 'planks': 0, 'stick': 0, 'stone': 0, 'stone_axe': 0, 'stone_pickaxe': 0, 'torch': 0, 'wooden_axe': 0, 'wooden_pickaxe': 0 }, 'pov': np.full([64, 64, 3], 127, dtype=np.uint8) } self.action_space = { 'attack': spaces.Discrete(2), 'back': spaces.Discrete(2), 'camera': spaces.Box(np.full([2], -1), np.full([2], 1)), 'craft': spaces.Enum('none', 'torch', 'stick', 'planks', 'crafting_table'), 'equip': spaces.Enum('none', 'air', 'wooden_axe', 'wooden_pickaxe', 'stone_axe', 'stone_pickaxe', 'iron_axe', 'iron_pickaxe'), 'forward': spaces.Discrete(2), 'jump': spaces.Discrete(2), 'left': spaces.Discrete(2), 'nearbyCraft': spaces.Enum('none', 'wooden_axe', 'wooden_pickaxe', 'stone_axe', 'stone_pickaxe', 'iron_axe', 'iron_pickaxe', 'furnace'), 'nearbySmelt': spaces.Enum('none', 'iron_ingot', 'coal'), 'place': spaces.Enum('none', 'dirt', 'stone', 'cobblestone', 'crafting_table', 'furnace', 'torch'), 'right': spaces.Discrete(2), 'sneak': spaces.Discrete(2), 'sprint': spaces.Discrete(2) } self.observation_space = { 'equipped_items': { 'mainhand': { 'damage': spaces.Box(np.full([2], -1), np.full([2], 1), dtype=np.int64), 'maxDamage': spaces.Box(np.full([2], -1), np.full([2], 1), dtype=np.int64), 'type': spaces.Enum('none', 'air', 'wooden_axe', 'wooden_pickaxe', 'stone_axe', 'stone_pickaxe', 'iron_axe', 'iron_pickaxe', 'other') } }, 'inventory': { 'coal': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'cobblestone': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'crafting_table': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'dirt': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'furnace': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'iron_axe': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'iron_ingot': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'iron_ore': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'iron_pickaxe': spaces.Box(np.full([1], -1), np.full([1], 1), dtype=np.int64), 'log': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'planks': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'stick': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'stone': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'stone_axe': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'stone_pickaxe': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'torch': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'wooden_axe': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64), 'wooden_pickaxe': spaces.Box(np.full([1], -1), np.full([1], -1), dtype=np.int64) }, 'pov': spaces.Box(np.full([64, 64, 3], -1), np.full([64, 64, 3], -1), dtype=np.uint8) } self.reward_range = (-np.inf, np.inf) self.metadata = {'render.modes': ['rgb_array', 'human']} self.t = 0