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

Add wizard mode option to play.py, refactor rendering logic. #226

Merged
merged 2 commits into from
Jul 22, 2021

Conversation

heiner
Copy link
Contributor

@heiner heiner commented Jul 22, 2021

No description provided.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 22, 2021
@heiner heiner requested a review from cdmatters July 22, 2021 11:55
@heiner heiner force-pushed the heiner/play-hard branch from 068fad1 to e758ebf Compare July 22, 2021 12:00
@heiner heiner force-pushed the heiner/play-hard branch from e758ebf to d7d4d24 Compare July 22, 2021 13:16
@@ -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):
Copy link
Contributor

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?

Copy link
Contributor

Choose a reason for hiding this comment

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

or reverse?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice idea. Done.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

Copy link
Contributor Author

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.

@@ -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.
Copy link
Contributor

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.

Suggested change
print("\033[33A") # Go back up.
print("\033[%dA" % (33)) # Go back up 33 lines.

Copy link
Contributor Author

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 ...

Copy link
Contributor Author

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.

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"]))
Copy link
Contributor

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?

Copy link
Contributor Author

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):
Copy link
Contributor

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"]
Copy link
Contributor

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?
Copy link
Contributor

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

Copy link
Contributor Author

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.

@heiner heiner merged commit 55792b8 into master Jul 22, 2021
@heiner heiner deleted the heiner/play-hard branch July 22, 2021 15:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants