Z-Machine

class textworld.envs.zmachine.frotz.DefaultZGameState(env=None)[source]

Bases: textworld.core.GameState

Create a game state.

Parameters:env (Optional[Environment]) – Environment that can be used to fetch additional information.
description

Description of the current location.

feedback

Interpreter’s response after issuing last command.

has_lost

Whether the player has lost the game or not.

has_won

Whether the player has won the game or not.

inventory

Player’s inventory.

max_score

Max score for this game.

nb_deaths

Number of times the player has died.

score

Current score.

class textworld.envs.zmachine.frotz.FrotzEnvironment(game_filename)[source]

Bases: textworld.core.Environment

Environment to support playing Z-Machine games.

FrotzEnvironment relies on the frotz interpreter which is started in a seperate process (using the Python subprocess module. Then, the FrotzEnvironment sends text commands via stdin and reads the output from stdout. This is known to cause some concurrency issues. For that reason textworld.envs.JerichoEnviroment is preferred.

Parameters:game_filename (str) – Path to the game file.
GAME_STATE_CLASS

alias of DefaultZGameState

close()[source]

Ends the game.

Return type:None
render(mode='human')[source]

Renders the current state of the game.

Parameters:mode (str) – The mode to use for rendering.
reset()[source]

Starts game from the beginning.

Return type:DefaultZGameState
Returns:Initial state of the game.
seed(seed)[source]

Sets the seed for the random number generator.

Return type:List[~T]
send(command)[source]

Send a command to the game and return the output.

Parameters:command (str) – Command to senf to Frotz (Z-machine’s interpreter).
Returns:The feeback message of the command sent.
Return type:str
step(command)[source]

Performs a given command.

Parameters:command (str) – Text command to send to the interpreter.
Return type:Tuple[DefaultZGameState, float, bool]
Returns: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.
metadata = {'render.modes': ['human', 'ansi', 'text']}
exception textworld.envs.zmachine.jericho.JerichoUnsupportedGameWarning[source]

Bases: UserWarning

class textworld.envs.zmachine.jericho.JerichoEnvironment(game_filename)[source]

Bases: textworld.core.Environment

Parameters:game_filename (str) – The game’s filename.
GAME_STATE_CLASS

alias of JerichoGameState

close()[source]

Ends the game.

render(mode='human', close=False)[source]

Renders the current state of the game.

Parameters:mode – The mode to use for rendering.
reset()[source]

Starts game from the beginning.

Returns:Initial state of the game.
seed(seed=None)[source]

Sets the seed for the random number generator.

step(command)[source]

Performs a given command.

Parameters:command – Text command to send to the interpreter.
Returns: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.
game_running

Determines if the game is still running.

Return type:bool
metadata = {'render.modes': ['human', 'ansi', 'text']}
class textworld.envs.zmachine.jericho.JerichoGameState(env=None)[source]

Bases: textworld.core.GameState

Create a game state.

Parameters:env (Optional[Environment]) – Environment that can be used to fetch additional information.
description

Description of the current location.

feedback

Interpreter’s response after issuing last command.

has_lost

Whether the player has lost the game or not.

has_won

Whether the player has won the game or not.

inventory

Player’s inventory.

max_score

Max score for this game.

nb_deaths

Number of times the player has died.

score

Current score.

class textworld.envs.zmachine.zork1.Zork1Environment(game_filename)[source]

Bases: textworld.envs.zmachine.frotz.FrotzEnvironment

Parameters:game_filename (str) – Path to the game file.
GAME_STATE_CLASS

alias of Zork1GameState

class textworld.envs.zmachine.zork1.Zork1GameState(env=None)[source]

Bases: textworld.core.GameState

Create a game state.

Parameters:env (Optional[Environment]) – Environment that can be used to fetch additional information.
description

Description of the current location.

feedback

Interpreter’s response after issuing last command.

has_lost

Whether the player has lost the game or not.

has_won

Whether the player has won the game or not.

inventory

Player’s inventory.

max_score

Max score for this game.

nb_deaths

Number of times the player has died.

score

Current score.