# Wrappers¶

class textworld.envs.wrappers.recorder.Recorder[source]
reset()[source]

Starts game from the beginning.

Return type: GameState Initial state of the game.
step(command)[source]

Performs a given command.

Parameters: command (str) – Text command to send to the interpreter. Tuple[GameState, float, bool] A tuple containing the new game state, a reward for performing that command and reaching this new state, and whether the game is finished or not.
class textworld.envs.wrappers.viewer.HtmlViewer(env, open_automatically=True, port=8080)[source]

Wrap a TextWorld environment to provide visualization.

During a playthrough, the game can be visualized via local webserver http://localhost:<port>.

:param : The TextWorld environment to wrap. :type : param env: :param : Port to use for the web viewer. :type : param port:

close()[source]

Close the game.

In addition to shutting down the game, this closes the local webserver.

reset()[source]

Reset the game.

Returns: Initial game state.
step(command)[source]

Perform a game step.

Parameters: command (str) – Text command to send to the game engine. Tuple[GameState, float, bool] game_state – Updated game state. score – Score for reaching this state. done – Whether the same is done or not.
class textworld.envs.wrappers.filter.EnvInfos(**kwargs)[source]

Bases: object

Customizing what information will be returned by an environment.

Information can be requested by setting one or more attributes to True. The attribute extras should be a list of strings corresponding to information specific to certain games.

admissible_commands

bool – All commands relevant to the current state. This information changes from one step to another.

basics

Information requested excluding the extras.

Return type: Iterable[str]
command_templates

bool – Templates for commands understood by the the game. This information doesn’t change from one step to another.

description

bool – Text description of the current room, i.e. output of the look command. This information changes from one step to another.

entities

bool – Names of all entities in the game. This information doesn’t change from one step to another.

extras

List[str] – Names of extra information which are game specific.

facts

bool – All the facts that are currently true about the world. This information changes from one step to another.

has_lost

bool – Whether the player lost the game. This information changes from one step to another.

has_won

bool – Whether the player won the game. This information changes from one step to another.

intermediate_reward

bool – Reward (proxy) indicating if the player is making progress. This information changes from one step to another.

inventory

bool – Text listing of the player’s inventory, i.e. output of the inventory command. This information changes from one step to another.

location

bool – Name of the player’s current location. This information changes from one step to another.

max_score

bool – Maximum reachable score of the game. This information doesn’t change from one step to another.

objective

bool – Objective of the game described in text. This information doesn’t change from one step to another.

policy_commands

bool – Sequence of commands leading to a winning state. This information changes from one step to another.

verbs

bool – Verbs understood by the the game. This information doesn’t change from one step to another.

class textworld.envs.wrappers.filter.Filter(options)[source]

Environment wrapper to filter what information is made available.

Requested information will be included within the infos dictionary returned by Filter.reset() and Filter.step(...). To request specific information, create a textworld.EnvInfos and set the appropriate attributes to True. Then, instantiate a Filter wrapper with the EnvInfos object.

Example

Here is an example of how to request information and retrieve it.

>>> from textworld import EnvInfos
>>> from textworld.envs.wrappers import Filter
>>> request_infos = EnvInfos(description=True, inventory=True, extras=["more"])
...
>>> env = Filter(env)
>>> ob, infos = env.reset()
>>> print(infos["description"])
>>> print(infos["inventory"])
>>> print(infos["extra.more"])

Parameters: options (EnvInfos) – For customizing the information returned by this environment (see textworld.EnvInfos for the list of available information).
reset()[source]

Starts game from the beginning.

Return type: Tuple[str, Mapping[str, Any]] Initial state of the game.
step(command)[source]

Performs a given command.

Parameters: command (str) – Text command to send to the interpreter. Tuple[str, float, bool, Mapping[str, Any]] A tuple containing the new game state, a reward for performing that command and reaching this new state, and whether the game is finished or not.