user3704648
user3704648

Reputation: 399

OpenAI gym player mode

Does anyone know how to run one of the OpenAI gym environments as a player. As in letting a human player play a round of cart pole? I have seen that there is env.mode = 'human' but I have not been able to get it to run properly. I have tried to follow the example given here https://www.pinchofintelligence.com/getting-started-openai-gym/ but it doesn't seem to work for me.

Any help you can give would be greatly appreciated.

Thanks

Upvotes: 14

Views: 7482

Answers (3)

neoneye
neoneye

Reputation: 52231

The openai/gym repo has been moved to the gymnasium repo.

PROMPT> pip install "gymnasium[atari, accept-rom-license]"

In order to launch a game in a playable mode. Start python in interactive mode, like this:

PROMPT> python

Then paste the following, line by line:

import gymnasium as gym
from gymnasium.utils.play import play
env = gym.make('ALE/Breakout-v5', render_mode='rgb_array')
play(env, zoom=3)

Keymap

  • Key a moves left.
  • Key d moves right.
  • Key space is fire.

To quit the game

exit()

More info on the Gymnasium Breakout page: https://gymnasium.farama.org/environments/atari/breakout/

It's not all environments that supports render_mode="rgb_array" and may fail to launch.

Upvotes: 3

wmatt
wmatt

Reputation: 795

I was experimenting with this today, hope this helps:

env = gym.make('Breakout-v0')
gym.utils.play.play(env, zoom=3)

Upvotes: 5

user3704648
user3704648

Reputation: 399

I found how to enable play mode for the environments.

https://github.com/openai/gym/blob/master/gym/utils/play.py

Upvotes: 4

Related Questions