Book Image

Unity 5.x Game AI Programming Cookbook

By : Jorge Palacios
5 (1)
Book Image

Unity 5.x Game AI Programming Cookbook

5 (1)
By: Jorge Palacios

Overview of this book

Unity 5 comes fully packaged with a toolbox of powerful features to help game and app developers create and implement powerful game AI. Leveraging these tools via Unity’s API or built-in features allows limitless possibilities when it comes to creating your game’s worlds and characters. This practical Cookbook covers both essential and niche techniques to help you be able to do that and more. This Cookbook is engineered as your one-stop reference to take your game AI programming to the next level. Get to grips with the essential building blocks of working with an agent, programming movement and navigation in a game environment, and improving your agent's decision making and coordination mechanisms - all through hands-on examples using easily customizable techniques. Discover how to emulate vision and hearing capabilities for your agent, for natural and humanlike AI behaviour, and improve them with the help of graphs. Empower your AI with decision-making functions through programming simple board games such as Tic-Tac-Toe and Checkers, and orchestrate agent coordination to get your AIs working together as one.
Table of Contents (15 chapters)
Unity 5.x Game AI Programming Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Predicting actions with an N-Gram predictor


Predicting actions is a great way to give players a challenge by going from random selection to selection based on past actions. One way to implement learning is by using probabilities in order to predict what the player will do next, and that's what an N-Gram predictor does.

To predict the next choice, N-Gram predictors hold a record of the probabilities of making a decision (which is usually a move), given all combinations of choices for the previous n moves.

Getting ready…

This recipe makes use of general types. It is recommended that we have at least a basic understanding of how they work because it's critical that we use them well.

The first thing to do is implement a data type for holding the actions and their probabilities; we'll call it KeyDataRecord.

The KeyDataReconrd.cs file should look like this:

using System.Collections;
using System.Collections.Generic;

public class KeyDataRecord<T>
{
    public Dictionary<T, int> counts;
...