Skip to content

Commit

Permalink
Add pause option to play to allow turn based games (#1042)
Browse files Browse the repository at this point in the history
  • Loading branch information
foreverska authored May 4, 2024
1 parent 5bf7269 commit 17f161e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion gymnasium/utils/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,12 @@ def play(
keys_to_action: dict[tuple[str | int, ...] | str | int, ActType] | None = None,
seed: int | None = None,
noop: ActType = 0,
wait_on_player: bool = False,
):
"""Allows the user to play the environment using a keyboard.
If playing in a turn-based environment, set wait_on_player to True.
Args:
env: Environment to use for playing.
transpose: If this is ``True``, the output of observation is transposed. Defaults to ``True``.
Expand Down Expand Up @@ -204,6 +207,7 @@ def play(
If ``None``, default ``key_to_action`` mapping for that environment is used, if provided.
seed: Random seed used when resetting the environment. If None, no seed is used.
noop: The action used when no key input has been entered, or the entered key combination is unknown.
wait_on_player: Play should wait for a user action
Example:
>>> import gymnasium as gym
Expand Down Expand Up @@ -283,7 +287,7 @@ def play(
if done:
done = False
obs = env.reset(seed=seed)
else:
elif wait_on_player is False or len(game.pressed_keys) > 0:
action = key_code_to_action.get(tuple(sorted(game.pressed_keys)), noop)
prev_obs = obs
obs, rew, terminated, truncated, info = env.step(action)
Expand Down

0 comments on commit 17f161e

Please sign in to comment.