How to do it...

Let's simulate the Atari environments by following these steps:

  1. To run any atari environment for the first time, we need to install the atari dependencies by running this command in the Terminal:
pip install gym[atari]

Alternatively, if you used the second approach in the previous recipe to install gym, you can run the following command instead:

pip install -e '.[atari]'
  1. After installing the Atari dependencies, we import the gym library in Python:
>>> import gym
  1. Create an instance of the SpaceInvaders environment:
>>> env = gym.make('SpaceInvaders-v0')
  1. Reset the environment:
>>> env.reset() array([[[ 0,  0, 0],         [ 0, 0,  0],         [ 0, 0,  0],         ...,         ...,         [80, 89, 22],         [80, 89, 22],         [80, 89, 22]]], dtype=uint8)

As you can ...

Get PyTorch 1.x Reinforcement Learning Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.