textworld.gym

textworld.gym.utils.make_batch(env_id, batch_size, parallel=False)[source]

Make an environment that runs multiple games independently.

Parameters:
  • env_id (str) – Environment ID that will compose a batch.
  • batch_size (int) – Number of independent environments to run.
  • parallel (bool) – If True, the environment will be executed in different processes.
Return type:

str

Returns:

The corresponding gym-compatible env_id to use.

textworld.gym.utils.register_game(game_file, request_infos=None, max_episode_steps=50, name='')[source]

Make an environment for a particular game.

Parameters:
  • game_file (str) – Path for the TextWorld game (.ulx).
  • request_infos (Optional[EnvInfos]) – For customizing the information returned by this environment (see textworld.EnvInfos for the list of available information).
  • max_episode_steps (int) – Terminate a game after that many steps.
  • name (str) – Name for the new environment, i.e. “tw-{name}-v0”. By default, the returned env_id is “tw-v0”.
Return type:

str

Returns:

The corresponding gym-compatible env_id to use.

Example

>>> from textworld.generator import make_game, compile_game
>>> options = textworld.GameOptions()
>>> options.seeds = 1234
>>> game = make_game(options)
>>> game.extras["more"] = "This is extra information."
>>> game_file = compile_game(game)

>>> import gym
>>> import textworld.gym
>>> from textworld import EnvInfos
>>> request_infos = EnvInfos(description=True, inventory=True, extras=["more"])
>>> env_id = textworld.gym.register_game(game_file, request_infos)
>>> env = gym.make(env_id)
>>> ob, infos = env.reset()
>>> print(infos["extra.more"])
This is extra information.
textworld.gym.utils.register_games(game_files, request_infos=None, max_episode_steps=50, name='')[source]

Make an environment that will cycle through a list of games.

Parameters:
  • game_files (List[str]) – Paths for the TextWorld games (.ulx).
  • request_infos (Optional[EnvInfos]) – For customizing the information returned by this environment (see textworld.EnvInfos for the list of available information).
  • max_episode_steps (int) – Terminate a game after that many steps.
  • name (str) – Name for the new environment, i.e. “tw-{name}-v0”. By default, the returned env_id is “tw-v0”.
Return type:

str

Returns:

The corresponding gym-compatible env_id to use.

Example

>>> from textworld.generator import make_game, compile_game
>>> options = textworld.GameOptions()
>>> options.seeds = 1234
>>> game = make_game(options)
>>> game.extras["more"] = "This is extra information."
>>> game_file = compile_game(game)

>>> import gym
>>> import textworld.gym
>>> from textworld import EnvInfos
>>> request_infos = EnvInfos(description=True, inventory=True, extras=["more"])
>>> env_id = textworld.gym.register_games([game_file], request_infos)
>>> env = gym.make(env_id)
>>> ob, infos = env.reset()
>>> print(infos["extra.more"])
This is extra information.