def play(env, transpose=True, fps=<NUM_LIT:30>, nop_=<NUM_LIT:0>):
<EOL>assert isinstance(env.observation_space, gym.spaces.box.Box)<EOL>obs_s = env.observation_space<EOL>is_bw = len(obs_s.shape) == <NUM_LIT:2><EOL>is_rgb = len(obs_s.shape) == <NUM_LIT:3> and obs_s.shape[<NUM_LIT:2>] in [<NUM_LIT:1>, <NUM_LIT:3>]<EOL>assert is_bw or is_rgb<EOL>if hasattr(env, '<STR_LIT>'):<EOL><INDENT>keys_to_action = env.get_keys_to_action()<EOL><DEDENT>elif hasattr(env.unwrapped, '<STR_LIT>'):<EOL><INDENT>keys_to_action = env.unwrapped.get_keys_to_action()<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>relevant_keys = set(sum(map(list, keys_to_action.keys()), []))<EOL>video_size = env.observation_space.shape[<NUM_LIT:0>], env.observation_space.shape[<NUM_LIT:1>]<EOL>if transpose:<EOL><INDENT>video_size = tuple(reversed(video_size))<EOL><DEDENT>pressed_keys = []<EOL>running = True<EOL>env_done = True<EOL>flags = pygame.RESIZABLE | pygame.HWSURFACE | pygame.DOUBLEBUF<EOL>screen = pygame.display.set_mode(video_size, flags)<EOL>pygame.event.set_blocked(pygame.MOUSEMOTION)<EOL>if env.spec is not None:<EOL><INDENT>pygame.display.set_caption(env.spec.id)<EOL><DEDENT>else:<EOL><INDENT>pygame.display.set_caption('<STR_LIT>')<EOL><DEDENT>clock = pygame.time.Clock()<EOL>while running:<EOL><INDENT>if env_done:<EOL><INDENT>env_done = False<EOL>obs = env.reset()<EOL><DEDENT>else:<EOL><INDENT>action = keys_to_action.get(tuple(sorted(pressed_keys)), nop_)<EOL>obs, rew, env_done, info = env.step(action)<EOL><DEDENT>if obs is not None:<EOL><INDENT>if len(obs.shape) == <NUM_LIT:2>:<EOL><INDENT>obs = obs[:, :, None]<EOL><DEDENT>if obs.shape[<NUM_LIT:2>] == <NUM_LIT:1>:<EOL><INDENT>obs = obs.repeat(<NUM_LIT:3>, axis=<NUM_LIT:2>)<EOL><DEDENT>display_arr(screen, obs, video_size, transpose)<EOL><DEDENT>for event in pygame.event.get():<EOL><INDENT>if event.type == pygame.KEYDOWN:<EOL><INDENT>if event.key in relevant_keys:<EOL><INDENT>pressed_keys.append(event.key)<EOL><DEDENT>elif event.key == <NUM_LIT>:<EOL><INDENT>running = False<EOL><DEDENT>elif event.key == ord('<STR_LIT:e>'):<EOL><INDENT>env.unwrapped._backup()<EOL><DEDENT>elif event.key == ord('<STR_LIT:r>'):<EOL><INDENT>env.unwrapped._restore()<EOL><DEDENT><DEDENT>elif event.type == pygame.KEYUP:<EOL><INDENT>if event.key in relevant_keys:<EOL><INDENT>pressed_keys.remove(event.key)<EOL><DEDENT><DEDENT>elif event.type == pygame.QUIT:<EOL><INDENT>running = False<EOL><DEDENT><DEDENT>pygame.display.flip()<EOL>clock.tick(fps)<EOL><DEDENT>pygame.quit()<EOL>
Play the game using the keyboard as a human.

    Args:
        env (gym.Env): the environment to use for playing
        transpose (bool): whether to transpose frame before viewing them
        fps (int): number of steps of the environment to execute every second
        nop_ (any): the object to use as a null op action for the environment

    Returns:
        None