The strategy that we discussed earlier is coded as follows:
- Download the ROM that contains the Space Invaders game and also install the retro package:
$ wget http://www.atarimania.com/roms/Roms.rar && unrar x Roms.rar && unzip Roms/ROMS.zip$ pip3 install gym-retro$ python3 -m retro.import ROMS/
- Create the environment and extract the observation space:
env=retro.make(game='SpaceInvaders-Atari2600')env.observation_space# Box(210,160,3)
- Build a function that preprocesses the frame (image/screenshot of the Space Invaders game):
def preprocess_frame(frame): # Greyscale frame gray = rgb2gray(frame) # Crop the screen (remove the part below the player) # [Up: Down, Left: right] cropped_frame = gray[8:-12,4:-12] # Normalize ...