diff --git a/gymnasium/utils/play.py b/gymnasium/utils/play.py index 53b882ffb..50678f9c1 100644 --- a/gymnasium/utils/play.py +++ b/gymnasium/utils/play.py @@ -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``. @@ -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 @@ -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)