Cartpole-v1 (human Play)
import gym
from gym.utils.play import play
play(gym.make("CartPole-v1"),keys_to_action={"a":(0,),"d":(1,)},zoom=1)
I've mapped the keys to action correctly but every time I run it, the game keeps restarting without allowing me to play. As soon as it starts, it restarts.
I assume you have used Gym v0.26.
A couple of things must be set right:
The
render_mode
must be set to 'rgb_array' or 'rgb_array_list'. Not specifying (i.e. None) will raise an AssertionError Furthermore, thekeys_to_action
parameter expects a dictionary with strings as keys and ints as values. Therefore the dictionary should look like{"a":0,"d":1}
, or it will raise an AssertionError. With these fixes, the window stays open and inputs via the keys is possible.