-
Notifications
You must be signed in to change notification settings - Fork 113
Add wizard mode option to play.py, refactor rendering logic. #226
Conversation
nle/nethack/nethack.py
Outdated
@@ -77,10 +77,24 @@ def _set_env_vars(options, hackdir, wizkit=None): | |||
os.environ["WIZKIT"] = os.path.join(hackdir, wizkit) | |||
|
|||
|
|||
def tty_render(chars, colors): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you add a (optional) cursor tothis? I believe cursor can be rendered with an underline effect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or reverse?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice idea. Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It underlines the f
a little bit because the cat and the hero are so close.
nle/scripts/play.py
Outdated
@@ -116,15 +117,13 @@ def play(): | |||
print("-" * 8) | |||
print(obs["blstats"]) | |||
if not FLAGS.print_frames_separately: | |||
print("\033[33A") # Go up 33 lines. | |||
print("\033[33A") # Go back up. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useful to keep the comment (and maybe even str.fromat the 33) so anyone hacking know which bitto edit to adjust that. I've done so a lot in past.
print("\033[33A") # Go back up. | |
print("\033[%dA" % (33)) # Go back up 33 lines. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Happy to splice the 33
in like you suggest, but this is the comment that is just bound to go out of sync, which is extra bad here since there's also the \033
here ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to make it more expressive by introducing a suggestive function.
nle/scripts/play.py
Outdated
print(line.tobytes().decode("utf-8")) | ||
print(blstats) | ||
obs = dict(zip(nle.nethack.OBSERVATION_DESC.keys(), obs)) | ||
print(nle.nethack.tty_render(obs["tty_chars"], obs["tty_colors"])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've cut message intentionally yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because tty_chars
has that data.
@@ -39,6 +39,10 @@ def no_echo(): | |||
termios.tcsetattr(0, termios.TCSAFLUSH, tt) | |||
|
|||
|
|||
def go_back(num_lines): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
||
class TestAuxillaryFunctions: | ||
def test_tty_render(self): | ||
text = ["DE", "HV"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍 👍
|
||
if mode in ("ansi", "string"): # Misnomer: This is the least ANSI of them all. | ||
chars = self.last_observation[self._observation_keys.index("chars")] | ||
# TODO: Why return a string here but print in the other branches? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning a string is useful for things like WANDB, loggers, etc i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But it kinda breaks the API (and pylint doesn't like it).
But okay.
No description provided.