Skip to content

Actions

We use a text action space by default, but wrappers can change this to a discrete one. Use DiscreteActionSpaceWrapper(env, commands=[...]) to specify your own commands, or DiscreteDirectionsWrapper(env) for the game's movement directions. Passing actions="directions" to make_env() applies DiscreteDirectionsWrapper for you.

from mudgym import make_env

env = make_env(actions="text")  # step("get axe")
env = make_env(actions="directions")  # step(3)

text

step() takes a non-empty string of up to 64 characters.

from mudgym import make_env

env = make_env(observation="parsed")
env.reset()
observation, reward, terminated, truncated, info = env.step("look")
env.close()

print(f"room_name  {observation['room_name']}")
print(f"reward     {reward}")
print(f"terminated {terminated}")
print(f"truncated  {truncated}")
room_name  narrow road between lands
reward     0.0
terminated False
truncated  False
Narrow road between lands. You are stood on a narrow road between The Land and whence you came. To the north and south are the small foothills of a pair of majestic mountains, with a large wall running round. To the west the road continues, where in the distance you can see a thatched cottage opposite an ancient cemetery. The way out is to the east, where a shroud of mist covers the secret pass by which you entered The Land. It is raining.

directions

Discrete(14) mapped onto move <direction> commands in the game's canonical exit order.

Index Command
0 move north
1 move east
2 move south
3 move west
4 move northeast
5 move southeast
6 move southwest
7 move northwest
8 move up
9 move down
10 move in
11 move out
12 move over
13 move swampward

observation["available_exits"][index] says whether the corresponding command is not known to be blocked in the current room, so you can use the parsed output as an action mask to avoid directions known to be unavailable.

import numpy as np

from mudgym import make_env
from mudgym.db.directions import DIRECTIONS

rng = np.random.default_rng(1)
env = make_env(observation="parsed", actions="directions")
observation, info = env.reset()

candidate_actions = np.flatnonzero(observation["available_exits"])
action = int(rng.choice(candidate_actions)) if len(candidate_actions) else int(env.action_space.sample())

observation, reward, terminated, truncated, info = env.step(action)
print(DIRECTIONS[action])
env.close()

Dark rooms report every exit

A dark room returns no exit line, and FEXitsField then reports all exits as available rather than none. A True means "not known to be blocked", not "known to be open".