minihack.base module

class minihack.base.MiniHack(*args: Any, **kwargs: Any)[source]

Bases: nle.env.tasks.

MiniHack base class.

All MiniHack environments are derived from this class, which itself is derived from NLE base class.

Note that this class itself is not used for creating new environment instances. Instead, MiniHackNavigation and MiniHackSkill provide a more convenient interface for doing this, both of which are directly derived from MiniHack for specific types of environments.

__init__(*args, des_file: str, reward_win=1, reward_lose=0, obs_crop_h=9, obs_crop_w=9, obs_crop_pad=0, reward_manager=None, use_wiki=False, autopickup=True, pet=False, observation_keys=['glyphs', 'chars', 'colors', 'specials', 'glyphs_crop', 'chars_crop', 'colors_crop', 'specials_crop', 'blstats', 'message'], seeds=None, include_see_actions=True, include_alignment_blstats=True, **kwargs)[source]

Constructs a new MiniHack environment.

  • des_file (str) – The description file for the environment.

  • reward_win (float) – The reward received upon successfully completing an episode. Defaults to 1.

  • reward_lose (float) – The reward received upon death or aborting. Defaults to 1.

  • obs_crop_h (int) – The height of agent-centred cropped observation. Defaults to 9.

  • obs_crop_w (int) – The width of agent-centred cropped observation. Defaults to 9.

  • obs_crop_pad (int) – The padding for agent-centred cropped observation. Defaults to 0.

  • reward_manager (RewardManager or None) – The reward manager that describes the custom reward function of the agent. If None, the goal of the agent is to reach the stair down. Defaults to None.

  • use_wiki (bool) – Whether to use the NetHack wiki. Defaults to False.

  • autopickup (bool) – Turning autopickup on or off. Defaults to True.

  • pet (bool) – Whether to include the pet. Defaults to False.

  • observation_keys (list) – The keys of observations returned after every timestep by the environment as a dictionary. Defaults to minihack.base.MH_DEFAULT_OBS_KEYS.

  • seeds (list or None) – A list of integers used as level seeds for sampling episodes. The reset()` function samples a seed from this list uniformly at random and uses it for setting the level. When the sample_seed argument of the reset function is set to False, a random level will not be sampled from this list during environment resetting. If None, the entire level distribution is used. Defaults to None.

  • penalty_mode (str) – The name of the mode for calculating the time step penalty. Can be constant, exp, square, linear, or always. Defaults to constant. Inherited from NetHackScore.

  • penalty_step (float) – A constant applied to amount of frozen steps. Defaults to -0.01. Inherited from NetHackScore.

  • penalty_time (float) – A constant applied to amount of frozen steps. Defaults to -0.0. Inherited from NetHackScore.

  • save_ttyrec_every (int) – Integer, if 0, no ttyrecs (game recordings) will be saved. Otherwise, save a ttyrec every Nth episode. Defaults to 0. Inherited from NLE.

  • savedir (str or None) – Path to save ttyrecs (game recordings) into, if save_ttyrec_every is nonzero. If nonempty string, interpreted as a path to a new or existing directory. If “” (empty string) or None, NLE choses a unique directory name. Defaults to None. Inherited from NLE.

  • character (str) – Name of character. Defaults to “mon-hum-neu-mal”. Interited from NLE.

  • max_episode_steps (int) – maximum amount of steps allowed before the game is forcefully quit. In such cases, info["end_status"] ill be equal to StepStatus.ABORTED. Defaults to 200. Inherited from NLE.

  • actions (list) – list of actions. If None, the full action space will be used, i.e. nle.nethack.ACTIONS. Defaults to MH_FULL_ACTIONS. Inherited from NLE.

  • wizard (bool) – activate wizard mode. Defaults to False. Inherited from NLE.

  • allow_all_yn_questions (bool) – If set to True, no y/n questions in step() are declined. If set to False, only elements of SKIP_EXCEPTIONS are not declined. Defaults to True. Inherited from NLE.

  • allow_all_modes (bool) – If set to True, do not decline menus, text input or auto ‘MORE’. If set to False, only skip click through ‘MORE’ on death. Defaults to False. Inherited from NLE.

  • spawn_monsters (bool) – If False, disables normal NetHack behavior to randomly create monsters. Defaults to False. Inherited from NLE.

  • include_see_actions (bool) – If True, the agent’s action space includes the additional NLE actions introduced in the 0.8.1 release. Has no effect when the actions parameter is specified. Defaults to True.

  • include_alignment_blstats (bool) – If True, the agent’s observation space includes the alignment information in the blstats. This is introduced in NLE 0.9.0 release. Defaults to True.


Returns the descriptions of nine neighboring grids around the agent.


Returns the page contents of the neighboring objects from NetHack wiki.

get_object_direction(name, observation=None)[source]

Find the game direction of the (first) object in the neighboring nine tiles that contains the given name in its description.

  • name (str) – Name of the object.

  • observation (dict) – Agent observation.


The index of the direction. None if not found.

Return type


get_screen_description(x, y, observation=None)[source]

Returns the description of the screen on (x,y) coordinates.

get_screen_wiki_page(x, y, observation=None)[source]

Returns the wiki page matching the object on (x,y) coordinates.


Returns key of the given object in the inventory.


name (str) – Name of the object.


the key of the first item in the inventory that includes the argument name as a substring. Returns None if not found.

Return type


reset(*args, sample_seed=True, **kwargs)[source]
screen_contains(name, observation=None)[source]

Whether an object with the given name is visible on the screen, i.e. included in the screen descriptions of the observation dictionary.

  • name (str) – Name of the object or monster.

  • observation (dict) – Agent observation.


True if the name is contained on the screen, False otherwise.

Return type


step(action: int)[source]

Update the current environment by replacing its description file.