Wrappers

class textworld.envs.wrappers.recorder.Recorder[source]

Bases: textworld.core.Wrapper

Parameters

env – environment to wrap.

reset()[source]
Return type

GameState

step(command)[source]
Return type

Tuple[GameState, float, bool]

class textworld.envs.wrappers.viewer.HtmlViewer(env, open_automatically=True, port=8080)[source]

Bases: textworld.core.Wrapper

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.

Return type

Initial game state.

step(command)[source]

Perform a game step.

Parameters

command (str) – Text command to send to the game engine.

Return type

Tuple[GameState, float, bool]

Returns

  • game_state – Updated game state.

  • score – Score for reaching this state.

  • done – Whether the same is done or not.

property port
class textworld.envs.wrappers.filter.Filter(env=None)[source]

Bases: textworld.core.Wrapper

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 = textworld.start(gamefile, request_infos)
>>> env = Filter(env)
>>> ob, infos = env.reset()
>>> print(infos["description"])
>>> print(infos["inventory"])
>>> print(infos["extra.more"])
Parameters

env (Optional[Environment]) – environment to wrap.

copy()[source]
Return type

Filter

reset()[source]
Return type

Tuple[str, Mapping[str, Any]]

step(command)[source]
Return type

Tuple[str, Mapping[str, Any]]