Implementation
You'll implement the entire AI code and the Snake game in five files:
environment.py
file – The file containing the environment (Snake game)brain.py
file – The file in which we build our CNNDQN.py
– The file that builds the Experience Replay Memorytrain.py
– The file where we will train our AI to play Snaketest.py
– The file where we will test our AI to see how well it performs
You can find all of them on the GitHub page along with a pre-trained model. To get there, select Chapter 13
folder on the main page.
We'll go through each file in the same order. Let's start building the environment!
Step 1 – Building the environment
Start this first, important step by importing the libraries you'll need. Like this:
# Importing the libraries #4
import numpy as np #5
import pygame as pg #6
You'll only use two libraries: NumPy and PyGame. The former...