- First, we import the necessary libraries, as follows:
import numpy as npimport gymimport tensorflow as tfimport matplotlib.pyplot as plt
- Let's set up the Pong environment and plot a frame:
Figures 5.1: Frame of the Pong game by OpenAI
env = gym.make("Pong-v0") # environment infoobservation = env.reset()for i in range(22): # The ball is released after 20 frames if i > 20: plt.imshow(observation) plt.show() # Get the next observation observation, _, _, _ = env.step(1)
- Before we implement the algorithm, we need a function that preprocesses the input data:
def preprocess_frame(frame): # remove top part of frame and some ...