Book Image

Hands-On Deep Learning for Games

By : Micheal Lanham
Book Image

Hands-On Deep Learning for Games

By: Micheal Lanham

Overview of this book

The number of applications of deep learning and neural networks has multiplied in the last couple of years. Neural nets has enabled significant breakthroughs in everything from computer vision, voice generation, voice recognition and self-driving cars. Game development is also a key area where these techniques are being applied. This book will give an in depth view of the potential of deep learning and neural networks in game development. We will take a look at the foundations of multi-layer perceptron’s to using convolutional and recurrent networks. In applications from GANs that create music or textures to self-driving cars and chatbots. Then we introduce deep reinforcement learning through the multi-armed bandit problem and other OpenAI Gym environments. As we progress through the book we will gain insights about DRL techniques such as Motivated Reinforcement Learning with Curiosity and Curriculum Learning. We also take a closer look at deep reinforcement learning and in particular the Unity ML-Agents toolkit. By the end of the book, we will look at how to apply DRL and the ML-Agents toolkit to enhance, test and automate your games or simulations. Finally, we will cover your possible next steps and possible areas for future learning.
Table of Contents (18 chapters)
Free Chapter
1
Section 1: The Basics
6
Section 2: Deep Reinforcement Learning
14
Section 3: Building Games

Playing Rock, Paper, Scissors with LSTMs

Remembering sequences of data have huge applications in many areas, not the least of which includes gaming. Of course, producing a simple, clean example is another matter. Fortunately, examples abound on the internet and Chapter_2_5.py shows an example of using an LSTM to play Rock, Paper, Scissors.

Open up that sample file and follow these steps:

This example was pulled from https://github.com/hjpulkki/RPS, but the code needed to be tweaked in several places to get it to work for us.
  1. Let's start as we normally do with the imports. For this sample, be sure to have Keras installed as we did for the last set of exercises:
import numpy as np
from keras.utils import np_utils
from keras.models import Sequential
from keras.layers import Dense, LSTM
  1. Then, we set some constants as shown:
EPOCH_NP = 100
INPUT_SHAPE = (1, -1, 1)
OUTPUT_SHAPE...