1"""A simple environment used in for the env building tutorial: 2[`hcraft.env`](https://irll.github.io/HierarchyCraft/hcraft/env.html) 3 4Requirements graph: 5<div class="graph"> 6.. include:: ../../../../docs/images/requirements_graphs/TreasureHcraft.html 7</div> 8 9""" 10 11from hcraft.examples.treasure.env import TreasureEnv 12 13__all__ = ["TreasureEnv"] 14 15# gym is an optional dependency 16try: 17 import gymnasium as gym 18 19 gym.register( 20 id="Treasure-v1", 21 entry_point="hcraft.examples.treasure.env:TreasureEnv", 22 ) 23 24 25except ImportError: 26 pass
API Documentation
class
TreasureEnv(typing.Generic[~ObsType, ~ActType]):
12class TreasureEnv(HcraftEnv): 13 """A simple environment used in for the env building tutorial.""" 14 15 TREASURE_ROOM = Zone("treasure_room") 16 """Room containing the treasure.""" 17 KEY_ROOM = Zone("key_room") 18 """Where all the keys are stored.""" 19 START_ROOM = Zone("start_room") 20 """Where the player starts.""" 21 22 CHEST = Item("treasure_chest") 23 """Treasure chest containing gold.""" 24 LOCKED_CHEST = Item("locked_chest") 25 """Treasure chest containing gold ... but it's locked.""" 26 GOLD = Item("gold") 27 """Gold! well the pixel version at least.""" 28 KEY = Item("key") 29 """A key ... it can probably unlock things.""" 30 31 def __init__(self, **kwargs) -> None: 32 transformations = self._build_transformations() 33 world = world_from_transformations( 34 transformations=transformations, 35 start_zone=self.START_ROOM, 36 start_zones_items={self.TREASURE_ROOM: [self.LOCKED_CHEST]}, 37 ) 38 world.resources_path = Path(__file__).parent / "resources" 39 super().__init__( 40 world, purpose=GetItemTask(self.GOLD), name="TreasureHcraft", **kwargs 41 ) 42 43 def _build_transformations(self) -> List[Transformation]: 44 TAKE_GOLD_FROM_CHEST = Transformation( 45 "take-gold-from-chest", 46 inventory_changes=[ 47 Use(CURRENT_ZONE, self.CHEST, consume=1), 48 Yield(PLAYER, self.GOLD), 49 ], 50 ) 51 52 SEARCH_KEY = Transformation( 53 "search-key", 54 inventory_changes=[ 55 Yield(PLAYER, self.KEY, max=1), 56 ], 57 zone=self.KEY_ROOM, 58 ) 59 60 UNLOCK_CHEST = Transformation( 61 "unlock-chest", 62 inventory_changes=[ 63 Use(PLAYER, self.KEY, 2), 64 Use(CURRENT_ZONE, self.LOCKED_CHEST, consume=1), 65 Yield(CURRENT_ZONE, self.CHEST), 66 ], 67 ) 68 69 MOVE_TO_KEY_ROOM = Transformation( 70 "move-to-key_room", 71 destination=self.KEY_ROOM, 72 zone=self.START_ROOM, 73 ) 74 MOVE_TO_TREASURE_ROOM = Transformation( 75 "move-to-treasure_room", 76 destination=self.TREASURE_ROOM, 77 zone=self.START_ROOM, 78 ) 79 MOVE_TO_START_ROOM = Transformation( 80 "move-to-start_room", 81 destination=self.START_ROOM, 82 ) 83 84 return [ 85 TAKE_GOLD_FROM_CHEST, 86 SEARCH_KEY, 87 UNLOCK_CHEST, 88 MOVE_TO_KEY_ROOM, 89 MOVE_TO_TREASURE_ROOM, 90 MOVE_TO_START_ROOM, 91 ]
A simple environment used in for the env building tutorial.
TreasureEnv(**kwargs)
31 def __init__(self, **kwargs) -> None: 32 transformations = self._build_transformations() 33 world = world_from_transformations( 34 transformations=transformations, 35 start_zone=self.START_ROOM, 36 start_zones_items={self.TREASURE_ROOM: [self.LOCKED_CHEST]}, 37 ) 38 world.resources_path = Path(__file__).parent / "resources" 39 super().__init__( 40 world, purpose=GetItemTask(self.GOLD), name="TreasureHcraft", **kwargs 41 )
Arguments:
- world: World defining the environment.
- purpose: Purpose of the player, defining rewards and termination. Defaults to None, hence a sandbox environment.
- invalid_reward: Reward given to the agent for invalid actions. Defaults to -1.0.
- render_window: Window using to render the environment with pygame.
- name: Name of the environement. Defaults to 'HierarchyCraft'.
- max_step: (Optional[int], optional): Maximum number of steps before episode truncation. If None, never truncates the episode. Defaults to None.
Inherited Members
- hcraft.env.HcraftEnv
- world
- invalid_reward
- max_step
- name
- render_window
- render_mode
- state
- current_step
- current_score
- cumulated_score
- episodes
- task_successes
- terminal_successes
- purpose
- metadata
- truncated
- observation_space
- action_space
- action_masks
- step
- render
- reset
- close
- all_behaviors
- solving_behavior
- planning_problem
- infos
- gymnasium.core.Env
- spec
- unwrapped
- np_random_seed
- np_random
- has_wrapper_attr
- get_wrapper_attr
- set_wrapper_attr