Ji Hwan Park
Ji Hwan Park

Reputation: 81

How to check out actions available in OpenAI gym environment?

It seems like the list of actions for Open AI Gym environments are not available to check out even in the documentation. For example, let's say you want to play Atari Breakout. The available actions will be right, left, up, and down.

print(env.action_space.n) If I print the number of actions available in action space, it prints 4 as I have expected. However, what I want to see is the list of actions such as right, up, punch(maybe, boxing-v1), jump etc... you name it.

Is there any way to check out?

Upvotes: 4

Views: 4626

Answers (3)

Jirayu Kaewprateep
Jirayu Kaewprateep

Reputation: 760

It is possible by game where Artati environment had Descrete 18 numbers that you may read from

print(env.env.get_action_meanings())
print(env.action_space.n)

Result:

A.L.E: Arcade Learning Environment (version +978d2ce)
[Powered by Stella]
['NOOP', 'FIRE', 'UP', 'RIGHT', 'LEFT', 'DOWN', 'UPRIGHT', 'UPLEFT', 'DOWNRIGHT', 'DOWNLEFT', 'UPFIRE', 'RIGHTFIRE', 'LEFTFIRE', 'DOWNFIRE', 'UPRIGHTFIRE', 'UPLEFTFIRE', 'DOWNRIGHTFIRE', 'DOWNLEFTFIRE']
Discrete(18)

Upvotes: 2

Ali Pardhan
Ali Pardhan

Reputation: 332

Here is what I do:

env = gym.make('CartPole-v1')
print(env.action_space.n)    # 2 
print(env.observation_space) # Box(-3.4028234663852886e+38, 3.4028234663852886e+38, (4,), float32)
observation = env.reset()    # n_observation = observation.shape[0] # 8 
help(env.unwrapped)

Upvotes: 1

BenedictWilkins
BenedictWilkins

Reputation: 1253

This does not work for all environments in gym but it does work for the ALE environments:

import gym
env = gym.make("Breakout-v0")
env.unwrapped.get_action_meanings()

Upvotes: 2

Related Questions