Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Make space_dict global to reuse outside nle. #139

Merged
merged 2 commits into from
Dec 4, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
160 changes: 95 additions & 65 deletions nle/env/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,99 @@

SKIP_EXCEPTIONS = (b"eat", b"attack", b"direction?", b"pray")

NLE_SPACE_ITEMS = (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for not making this a dict already? Immutability?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly. Modifying the default object seems dangerous.

(
"glyphs",
gym.spaces.Box(
low=0, high=nethack.MAX_GLYPH, **nethack.OBSERVATION_DESC["glyphs"]
),
),
("chars", gym.spaces.Box(low=0, high=255, **nethack.OBSERVATION_DESC["chars"])),
("colors", gym.spaces.Box(low=0, high=15, **nethack.OBSERVATION_DESC["colors"])),
(
"specials",
gym.spaces.Box(low=0, high=255, **nethack.OBSERVATION_DESC["specials"]),
),
(
"blstats",
gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["blstats"],
),
),
(
"message",
gym.spaces.Box(
low=np.iinfo(np.uint8).min,
high=np.iinfo(np.uint8).max,
**nethack.OBSERVATION_DESC["message"],
),
),
(
"program_state",
gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["program_state"],
),
),
(
"internal",
gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["internal"],
),
),
(
"inv_glyphs",
gym.spaces.Box(
low=0,
high=nethack.MAX_GLYPH,
**nethack.OBSERVATION_DESC["inv_glyphs"],
),
),
(
"inv_strs",
gym.spaces.Box(low=0, high=127, **nethack.OBSERVATION_DESC["inv_strs"]),
),
(
"inv_letters",
gym.spaces.Box(low=0, high=127, **nethack.OBSERVATION_DESC["inv_letters"]),
),
(
"inv_oclasses",
gym.spaces.Box(
low=0,
high=nethack.MAXOCLASSES,
**nethack.OBSERVATION_DESC["inv_oclasses"],
),
),
(
"screen_descriptions",
gym.spaces.Box(
low=0, high=127, **nethack.OBSERVATION_DESC["screen_descriptions"]
),
),
(
"tty_chars",
gym.spaces.Box(low=0, high=127, **nethack.OBSERVATION_DESC["tty_chars"]),
),
(
"tty_colors",
gym.spaces.Box(
low=-15,
high=15,
**nethack.OBSERVATION_DESC["tty_colors"],
),
),
(
"tty_cursor",
gym.spaces.Box(low=0, high=255, **nethack.OBSERVATION_DESC["tty_cursor"]),
),
)


class NLE(gym.Env):
"""Standard NetHack Learning Environment.
Expand Down Expand Up @@ -115,6 +208,7 @@ def __init__(
options=None,
wizard=False,
allow_all_yn_questions=False,
space_dict=None,
):
"""Constructs a new NLE environment.

Expand Down Expand Up @@ -225,71 +319,7 @@ def __init__(
# -1 so that it's 0-based on first reset
self._episode = -1

space_dict = {
"glyphs": gym.spaces.Box(
low=0, high=nethack.MAX_GLYPH, **nethack.OBSERVATION_DESC["glyphs"]
),
"chars": gym.spaces.Box(
low=0, high=255, **nethack.OBSERVATION_DESC["chars"]
),
"colors": gym.spaces.Box(
low=0, high=15, **nethack.OBSERVATION_DESC["colors"]
),
"specials": gym.spaces.Box(
low=0, high=255, **nethack.OBSERVATION_DESC["specials"]
),
"blstats": gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["blstats"],
),
"message": gym.spaces.Box(
low=np.iinfo(np.uint8).min,
high=np.iinfo(np.uint8).max,
**nethack.OBSERVATION_DESC["message"],
),
"program_state": gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["program_state"],
),
"internal": gym.spaces.Box(
low=np.iinfo(np.int32).min,
high=np.iinfo(np.int32).max,
**nethack.OBSERVATION_DESC["internal"],
),
"inv_glyphs": gym.spaces.Box(
low=0,
high=nethack.MAX_GLYPH,
**nethack.OBSERVATION_DESC["inv_glyphs"],
),
"inv_strs": gym.spaces.Box(
low=0, high=127, **nethack.OBSERVATION_DESC["inv_strs"]
),
"inv_letters": gym.spaces.Box(
low=0, high=127, **nethack.OBSERVATION_DESC["inv_letters"]
),
"inv_oclasses": gym.spaces.Box(
low=0,
high=nethack.MAXOCLASSES,
**nethack.OBSERVATION_DESC["inv_oclasses"],
),
"screen_descriptions": gym.spaces.Box(
low=0, high=127, **nethack.OBSERVATION_DESC["screen_descriptions"]
),
"tty_chars": gym.spaces.Box(
low=0, high=127, **nethack.OBSERVATION_DESC["tty_chars"]
),
"tty_colors": gym.spaces.Box(
low=-15,
high=15,
**nethack.OBSERVATION_DESC["tty_colors"],
),
"tty_cursor": gym.spaces.Box(
low=0, high=255, **nethack.OBSERVATION_DESC["tty_cursor"]
),
}

space_dict = dict(NLE_SPACE_ITEMS) if space_dict is None else space_dict
self.observation_space = gym.spaces.Dict(
{key: space_dict[key] for key in observation_keys}
)
Expand Down