Book Image

Hands-On Reinforcement Learning for Games

By : Micheal Lanham
Book Image

Hands-On Reinforcement Learning for Games

By: Micheal Lanham

Overview of this book

With the increased presence of AI in the gaming industry, developers are challenged to create highly responsive and adaptive games by integrating artificial intelligence into their projects. This book is your guide to learning how various reinforcement learning techniques and algorithms play an important role in game development with Python. Starting with the basics, this book will help you build a strong foundation in reinforcement learning for game development. Each chapter will assist you in implementing different reinforcement learning techniques, such as Markov decision processes (MDPs), Q-learning, actor-critic methods, SARSA, and deterministic policy gradient algorithms, to build logical self-learning agents. Learning these techniques will enhance your game development skills and add a variety of features to improve your game agent’s productivity. As you advance, you’ll understand how deep reinforcement learning (DRL) techniques can be used to devise strategies to help agents learn from their actions and build engaging games. By the end of this book, you’ll be ready to apply reinforcement learning techniques to build a variety of projects and contribute to open source applications.
Table of Contents (19 chapters)
1
Section 1: Exploring the Environment
7
Section 2: Exploiting the Knowledge
15
Section 3: Reward Yourself

Building neural networks with Torch

In the last section, we explored building computational graphs that resemble neural networks. This is a fairly common task as you may expect. So much so that PyTorch, as well as most DL frameworks, provides helper methods, classes, and functions to build DL graphs. Keras is essentially a wrapper around TensorFlow that does just that. Therefore, in this section, we are going to recreate the last exercise's example using the neural network helper functions in PyTorch. Open the Chapter_6_2.py code example and follow the next exercise:

  1. The source code for the entire sample is as follows:
import torch

batch_size, inputs, hidden, outputs = 64, 1000, 100, 10

x = torch.randn(batch_size, inputs)
y = torch.randn(batch_size, outputs)

model = torch.nn.Sequential(
torch.nn.Linear(inputs, hidden),
torch.nn.ReLU(),
torch.nn.Linear(hidden, outputs)...