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, **kwargs)[source]

Constructs a new MiniHack environment.

Parameters
  • 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 random seeds for sampling episodes. 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.

  • savedir (str or None) – path to save ttyrecs (game recordings) into. Defaults to None, which doesn’t save any data. Otherwise, interpreted as a path to a new or existing directory. If “” (empty string), NLE choses a unique directory name. 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 5000. Inherited from NLE.

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

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

  • 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 False. 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. Inherited from NLE.

get_neighbor_descriptions(observation=None)[source]

Returns the descriptions of nine neighboring grids around the agent.

get_neighbor_wiki_pages(observation=None)[source]

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.

Parameters
  • name (str) – Name of the object.

  • observation (dict) – Agent observation.

Returns

The index of the direction. None if not found.

Return type

int

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.

key_in_inventory(name)[source]

Returns key of the given object in the inventory.

Parameters

name (str) – Name of the object.

Returns

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

Return type

str

reset(*args, **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.

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

  • observation (dict) – Agent observation.

Returns

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

Return type

bool

step(action: int)[source]
update(des_file)[source]

Update the current environment by replacing its description file.