Beispiel #1
0
def get_action(env, action_mode, is_raw_env):
    if action_mode == "random":
        if not is_raw_env:
            action = env.action_space.sample()
        else:
            action = random.choice(_ACTIONS)
    elif action_mode == "human":
        while True:
            with no_echo():
                ch = ord(os.read(0, 1))
            if ch in [nethack.C("c"), ord(b"q")]:
                print("Received exit code {}. Aborting.".format(ch))
                return None
            try:
                if is_raw_env:
                    action = ch
                else:
                    action = env._actions.index(ch)
                break
            except ValueError:
                print(
                    ("Selected action '%s' is not in action list. Please try again.")
                    % chr(ch)
                )
                continue
    return action
Beispiel #2
0
def get_action(env, is_raw_env):
    if FLAGS.mode == "random":
        if not is_raw_env:
            action = env.action_space.sample()
        else:
            action = random.choice(_ACTIONS)
            print(action)
    elif FLAGS.mode == "human":
        while True:
            with no_echo():
                ch = ord(os.read(0, 1))
            if ch in [nethack.C("c")]:
                print("Received exit code {}. Aborting.".format(ch))
                return None
            try:
                if is_raw_env:
                    action = ch
                else:
                    action = env.actions.index(ch)
                break
            except ValueError:
                print((
                    "Selected action '%s' is not in action list. Please try again."
                ) % chr(ch))
                if not FLAGS.print_frames_separately:
                    print("\033[2A")  # Go up 2 lines.
                continue
    return action
Beispiel #3
0
    def key_handler(event):
        if event.key == "escape":
            window.close()
            return

        if event.key == "backspace":
            reset()
            return

        if event.key.startswith("ctrl+"):
            ch = nethack.C(event.key[5])
        else:
            ch = ord(event.key)

        try:
            action = env._actions.index(ch)
            step(action)
        except (ValueError, TypeError):
            print(
                f"Selected action {event.key} is not in action list. Please try again."
            )
Beispiel #4
0
INVFIELDS = [
    "Glyph",
    "Str",
    "Letter",
    "ObjectClass",
    # "ObjectClassName",
]

DEFAULT_MSG_PAD = 256
DEFAULT_INV_PAD = 55
DEFAULT_INVSTR_PAD = 80

ASCII_SPACE = ord(" ")
ASCII_y = ord("y")
ASCII_n = ord("n")
ASCII_ESC = nethack.C("[")

FULL_ACTIONS = list(nethack.ACTIONS)
# Removing some problematic actions
FULL_ACTIONS.remove(nethack.Command.SAVE)
# TODO: consider re-adding help eventually, when we can handle its state machine
# and output.
FULL_ACTIONS.remove(nethack.Command.HELP)
FULL_ACTIONS = tuple(FULL_ACTIONS)


# TODO(NN): this logic should be refactored into a class with pythonic access to
# its attributes.
def _get(response, path="Blstats.score", default=None, required=False):
    node = response