Environment construction procedure for the gym "Open AI Gym" that trains AI in games on Mac OS X

OpenAI Gym is a platform for developing and evaluating artificial intelligence in games.

-OpenAI opens "training gym for AI" | WIRED.jp

You can build the environment just by doing pip install or brew install according to the procedure.

Pac-Man,

pacman.gif

Space Invaders,

invaders.gif

If you just try this kind of thing at random as a trial, you can do it with about 5 lines of code **, so I don't know about reinforcement learning at all, but it may be a good first step to try it for the time being. Maybe.

Below are the steps I took on ** macOS Sierra ** to build the environment.

Install OpenAI Gym

The installation procedure is described in the README here.

git clone https://github.com/openai/gym.git
cd gym
pip install -e .

In addition, it will fully install the dependent libraries and so on.

$ brew install cmake boost boost-python sdl2 swig wget

Atari environment installation

Install it additionally so that it can handle atari games.

$ pip install 'gym[atari]'

Operation check

A simple sample can be found in the Official Documentation (https://gym.openai.com/docs).

cartpole.py


import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample())

When I run it,

$ python cartpole.py

Such a game is executed.

Try to start various games

Space Invaders

code

invaders.py


import gym
env = gym.make('SpaceInvaders-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample())

Run

$ python invaders.py

invaders.gif

Pac-Man

code

pacman.py


import gym
env = gym.make('MsPacman-v0')
env.reset()
for _ in range(1000):
    env.render()
    env.step(env.action_space.sample())

Run

$ python pacman.py

pacman.gif

in conclusion

This time, I tried to build the environment and check the operation easily. I haven't stepped into the essential reinforcement learning by a millimeter yet, so I'd like to write it in another article.

Reference article:

Recommended Posts

Environment construction procedure for the gym "Open AI Gym" that trains AI in games on Mac OS X
Building an environment for "Tello_Video" on Mac OS X
Continuation ・ Notes on preparing the Python development environment on Mac OS X
Mac OS X Mavericks 10.9.5 Development environment construction
Mac OS X Yosemite 10.10 Development environment construction
Mac OS X development environment construction memo
Mac OS X Mountain Lion 10.8.5 Development environment construction
I installed Pygame with Python 3.5.1 in the environment of pyenv on OS X
Build a Python development environment on Mac OS X
VScode environment construction (on Mac) & graph display in Python (@browser)
Memo on Mac OS X
Ansible environment construction For Mac
Get started with the Python framework Django on Mac OS X
Anaconda environment construction on Mac (2018 version)
Install Sphinx on Mac OS X
Python environment construction memo on Mac
Install mitmproxy on Mac OS X
Environment construction of python3.8 on mac
Python3 TensorFlow for Mac environment construction
Install pgmagick on Mac OS X 10.9
Introduction to Graph Database Neo4j in Python for Beginners (for Mac OS X)
Python project environment construction procedure (for windows)
Installed aws-cli On Mac OS X Lion
Prepare the development environment for keyhac for Mac
Run NASA CEA on Mac OS X
Create a Python development environment in 10 minutes (Mac OS X + Visual Studio Code)
R environment construction with Jupyter (formerly IPython notebook) (on OS X El Capitan 10.11.3)
Run Qiita API v2 Python wrapper in Python3 environment (Mac OS X 10.11 (El Capitan))