Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Practical Game AI Programming
Practical Game AI Programming

Practical Game AI Programming: Unleash the power of Artificial Intelligence to your game

Arrow left icon
Profile Icon DaGraça
Arrow right icon
€18.99 per month
Paperback Jun 2017 348 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
Arrow left icon
Profile Icon DaGraça
Arrow right icon
€18.99 per month
Paperback Jun 2017 348 pages 1st Edition
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m
eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Practical Game AI Programming

Possibility and Probability Maps

In this chapter, we'll be talking about possibility and probability maps, understanding how and where they are used. We'll also be learning the best practices for creating an AI that reacts to the player and that also chooses the best options, as we look to create a character that can make decisions as a human would.

As we saw previously, video games used to rely heavily on predetermining the behavior of what the AI could do in different scenarios that were either created by the game itself or by the player's actions. This method has been present since day one and is still being used today, making it an extremely valuable method for creating quality AI characters. Before explaining, in detail, what each of the maps do, and before demonstrating how to create them in order to develop good AI behavior, it's always good to have...

Game states

To understand how to create possibility or probability maps we need to first acknowledge the principle aspect necessary to create them, which is called game states, or simply states. We call game states to the actions that are predetermined throughout different occasions in the game, and those actions can be applied to both the player or to the enemy character. Some examples can be simple behavior, such as run, jump, or attack, and those states can be expanded a little more, for example when the character is in the air and cannot attack or if the character has low magical energy and cannot perform a magic attack. In these cases, the character goes from one state to another or can't perform one if it's doing another.

Possibility maps

Now let's take a deeper look at the possibility maps that we encountered in the examples in the first chapter, from the chess machine to the Metal Gear Solid video game. As we can see, it's a technique that is still being used today, and it is almost impossible to create a game AI without it.

As the name suggests, possibility maps allow the programmer to define the possibilities available to the player or the AI character within the game. Everything that is possible inside the game needs to be planned and coded, but what happens when you allow the character to do a lot of things can they do them all at the same time? If played during different stages of the game, can they react in the same way at all of the stages? To allow, and restrain, the possible actions, we also need to think about the possible scenarios that can occur in the game, and when you...

Defining the states

Let's define what triggers each state and how the AI should choose the correct state in different scenarios. The PASSIVE state will be the default state, and the game will start in that position until the player comes across our character. The DEFENSIVE state will be used in two different situations if the player comes from the right side and if he has already confronted the player and has low HP. Finally, the AGGRESSIVE state will be activated if the player comes from the left side or has already arrived at the middle area:

public class Enemy : MonoBehaviour {
private int Health = 100;
private bool statePassive;
private bool stateAggressive;
private bool stateDefensive;
private bool triggerL;
private bool triggerR;
private bool triggerM;
// Use this for initialisation
void Start () {
statePassive = true;
}
// Update is called once per frame
void Update ...

Probability maps

A probability map is a more complex and detailed version of a possibility map because it relies on probabilities in order to change the behavior of the character, rather than a simple on or off trigger. Its similarity with the possibility map is that it's also required for planning ahead the possible states for our character. This time, however, we add to it a percentage, using which the AI will calculate what behavior he will be using. Imagine the next example using the situation that we previously created for the possibility map our enemy AI could be more aggressive in the daytime than at night. For that, we create a statement that explains to our enemy that if it's night time, there is a lesser chance of seeing the player character, and for that reason it will choose a more defensive approach instead of an aggressive one. Or, simply, we could define...

Summary

This chapter has described possibility and probability maps and we have learned how to let the AI take decisions for itself according to the player actions. Possibility and probability maps is the foundation of an AI character and now we can explore this technique to create new and unique artificial intelligence for our games. In the next chapter, we'll learn how the AI should behave according to the different options that it has on that moment instead of using a possibility map. We want the character to analyze the situation and think about what to do, taking in consideration many factors, such as health, distance, weapon, bullets, and any other relevant factors.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Move beyond using libraries to create smart game AI, and create your own AI projects from scratch
  • Implement the latest algorithms for AI development and in-game interaction
  • Customize your existing game AI and make it better and more efficient to improve your overall game performance

Description

The book starts with the basics examples of AI for different game genres and directly jumps into defining the probabilities and possibilities of the AI character to determine character movement. Next, you’ll learn how AI characters should behave within the environment created. Moving on, you’ll explore how to work with animations. You’ll also plan and create pruning strategies, and create Theta algorithms to find short and realistic looking game paths. Next, you’ll learn how the AI should behave when there is a lot of characters in the same scene. You'll explore which methods and algorithms, such as possibility maps, Forward Chaining Plan, Rete Algorithm, Pruning Strategies, Wall Distances, and Map Preprocess Implementation should be used on different occasions. You’ll discover how to overcome some limitations, and how to deliver a better experience to the player. By the end of the book, you think differently about AI.

Who is this book for?

This book is for game developers with a basic knowledge of game development techniques and some basic programming techniques in C# or C++.

What you will learn

  • Get to know the basics of how to create different AI for different type of games
  • Know what to do when something interferes with the AI choices and how the AI should behave if that happens
  • Plan the interaction between the AI character and the environment using Smart Zones or Triggering Events
  • Use animations correctly, blending one animation into another and rather than stopping one animation and starting another
  • Calculate the best options for the AI to move using Pruning Strategies, Wall Distances, Map Preprocess Implementation, and Forced Neighbours
  • Create Theta algorithms to the AI to find short and realistic looking paths
  • Add many characters into the same scene and make them behave like a realistic crowd

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 30, 2017
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781787122819
Vendor :
Unity Technologies
Languages :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Jun 30, 2017
Length: 348 pages
Edition : 1st
Language : English
ISBN-13 : 9781787122819
Vendor :
Unity Technologies
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 111.97
Practical Game AI Programming
€41.99
Game Development Patterns and Best Practices
€36.99
Game Physics Cookbook
€32.99
Total 111.97 Stars icon

Table of Contents

10 Chapters
Different Problems Require Different Solutions Chevron down icon Chevron up icon
Possibility and Probability Maps Chevron down icon Chevron up icon
Production System Chevron down icon Chevron up icon
Environment and AI Chevron down icon Chevron up icon
Animation Behaviors Chevron down icon Chevron up icon
Navigation Behavior and Pathfinding Chevron down icon Chevron up icon
Advanced Pathfinding Chevron down icon Chevron up icon
Crowd Interactions Chevron down icon Chevron up icon
AI Planning and Collision Avoidance Chevron down icon Chevron up icon
Awareness Chevron down icon Chevron up icon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.