Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
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

eBook
€22.99 €32.99
Paperback
€41.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Table of content icon View table of contents Preview book icon Preview Book

Practical Game AI Programming

Different Problems Require Different Solutions

 

A brief history of and solutions to game AI

To better understand how to overcome the problems that game developers are currently facing, we need to dig a little bit into the history of video game development and take a look at the problems and their solutions that were so important at the time. Some of them were so avant-garde that they actually changed the entire history of video game design itself, and we still use the same methods today to create unique and enjoyable games.

One of the first relevant marks that is always worth mentioning when talking about game AI is computer chess programmed to compete against humans. It was the perfect game to start experimenting with artificial intelligence, because chess usually requires a lot of thought and planning ahead, something that a computer couldn't do at the time because it was necessary to have human features in order to successfully play and win the game. So, the first step was to make it able for the computer to process the game rules and think for itself in order to make a good judgement of the next move that the computer should do to achieve the final goal, that is, winning by checkmating. The problem is that chess has many possibilities; so, even if the computer had a perfect strategy to beat the game, it was necessary to recalculate that strategy, adapting it, changing, or even creating a new one every time something went wrong with the first strategy.

Humans can play differently every time; this makes it a huge task for the programmers to input all the possible data into the computer in order to win the game. So, writing all the possibilities that could exist wasn't a viable solution, and because of that, the programmers needed to think again about the problem. Then, one day, they finally came out with a better solution, that is, to make the computer decide for itself every turn, choosing the most plausible option for each turn; that way, the computer could adapt to any possibility in the game. Yet, this involved another problem–the computer would only think the short-term moves, and not create any plans to defeat the human in the future moves; so, it was easy to play against it, but at least we started to have something going on. It was decades later that someone defined the word Artificial Intelligence (AI) by solving the first problem that many researchers had by trying to create a computer that was capable of defeating a human player. Arthur Samuel is the person responsible for creating a computer that could learn for itself and memorize all the possible combinations. That way, there wasn't necessarily any human intervention and the computer could actually think on its own, and that was a huge step that is still impressive even by today's standards.

Enemy AI in video games

Now, let's move to the video game industry and analyze how the first enemies and game obstacles were programmed; was it that different from what we are doing now? Let's find out.

Single-player games with AI enemies started to appear in the 1970s, and soon, some games started to elevate the quality and expectations of what defines a video game AI. Some of those examples were released for arcade machines, such as Speed Race from Taito (a racing video game), or Qwak (a duck hunting game using a light gun), and Pursuit (an aircraft fighter) both from Atari. Other notable examples are the text-based games released for the first personal computers, such as Hunt the Wumpus and Star Trek, which also had enemies. What made those games so enjoyable was precisely that the AI enemies that didn't reacted like any other before because they had random elements mixed with the traditional stored patterns, making them unpredictable, and hence providing a unique experience every time you played the game. However, that was only possible due to the incorporation of microprocessors that expanded the capabilities of a programmer at that time. Space Invaders brought the movement patterns and Galaxian improved and added more variety, making the AI even more complex. PAC-MAN later on brought movement patterns to the maze genre.

The influence that the AI design in PAC-MAN had is just as significant as the influence of the game itself. This classic arcade game makes the player believe that the enemies in the game are chasing him, but not in a crude manner. The ghosts are chasing the player (or evading the player) in a different way as if they have an individual personality. This gives people the illusion that they are actually playing against four or five individual ghosts rather than copies of the same computer enemy.

After that, Karate Champ introduced the first AI fighting character and Dragon Quest introduced the tactical system for the RPG genre; over the years, the list of games that explored artificial intelligence and used it to create unique game concepts kept expanding, and all of that came from a single question, how can we make a computer capable of beating a human in a game?

All the games mentioned above are of a different genre, and they are unique in their style, but all of them used the same method for the AI called finite-state machine (FSM). Here, the programmer inputs all the behaviors necessary for the computer to challenge the player, just like the computer that first played chess. The programmer defined exactly how the computer should behave on different occasions in order to move, avoid, attack, or perform any other behavior to challenge the player, and that method is used even in the latest big budget games of

From simple to smart and human-like AI

Programmers face many challenges while developing an AI character, but one of the greatest challenges is adapting the AI movement and behavior in relation to what the player is currently doing, or will do in future actions. The difficulty exists because the AI is programmed with predetermined states, using probability or possibility maps in order to adapt their movement and behavior according to the player. This technique can become very complex if the programmer extends the possibilities of the AI decisions, just like the chess machine that has all the possible situations that may occur in the game.

It's a huge task for the programmer because it's necessary to determine what the player can do and how the AI will react to each action of the player, and that takes a lot of CPU power. To overcome that challenge, programmers started to mix possibility maps with probabilities and perform other techniques that let the AI decide for itself on how it should react according to the player's actions. These factors are important to be considered while developing an AI that elevates the game quality as we are about to discover.

Games kept evolving and players got even more exigent, not only with the visual quality but also with the capabilities of the AI enemies and the allied characters. To deliver new games that took into consideration the player expectations, programmers started to write even more states for each character, creating new possibilities and more engaging enemies, implementing important allied characters, which meant more things for the player to do, and creating a lot more features that helped redefine different genres and created new ones. Of course, this was also possible because technology kept improving, allowing developers to explore even more artificial intelligence in video games. A great example of this that is worth mentioning is Metal Gear Solid, the game that brought a new genre to the video game industry by implementing stealth elements, instead of the popular straightforward shooting. However, those elements couldn't be fully explored as Hideo Kojima intended because of the hardware limitations at the time. Jumping forward from the third to the fifth generation of consoles, Konami and Hideo Kojima presented the same title, but this time with a lot more interactions, possibilities, and behaviors from the AI elements of the game, making it so successful and important in video game history that it's easy to see its influence in a large number of games that came after Metal Gear Solid:

Metal Gear Solid - Sony Playstation 1

Visual and audio awareness

The game in the preceding screenshot implemented visual and audio awareness for the enemy AI, a feature that later on we'll explore in detail in this book. This feature established the genre that we know today as a stealth game. So, the game uses Path Finding and a FSM, features that were already known from the beginning of the video game industry; But, in order to create something new, they also created new features, such as interaction with the environment, navigation behavior, visual/audio awareness, and AI interaction; a lot of things that didn't existed at the time but that are widely used today in different game genres, such as sports, racing, fighting, or FPS games, were also introduced:

After that huge step for game design, developers still faced other problems, or should I say, these new possibilities brought even more problems, because they were not perfect. The AI still didn't react as a real person, and many other elements was necessary to be implemented, not only in stealth games, but in all other genres, and one in particular-needed to improve their AI to make the game feel realistic.

We are talking about sports games, especially those that tried to simulate real-world team behaviors, such as basketball or football. interaction with the player is not the only thing that we need to care about; we left chess long time ago, where it was 1 versus 1. Now, we want more, and watching other games get realistic AI behaviors, sport fanatics started to ask for the same features in their

favorite games; after all, those games was based on real-world events, and for that reason, the AI should react as realistically as possible.

At this point, developers and game designers started to take into consideration AI interaction with itself, and that just like the enemies from PAC-MAN, the player should get the impression that each character in the game thinks for itself and reacts differently to the others. If we analyze it closely, the AI that is present in a sports game is structured like an FPS or RTS game, using different animation states, general movements, interactions, individual decisions, and finally tactics and collective decisions. So, it shouldn't be a surprise that sports games could reach the same level of realism as the other genres that had already greatly evolved in terms of AI development. However, there are few problems that only sports games had at the time: how to make so many characters on the same screen react differently but at the same time work together to achieve the same objective. With this problem in mind, developers started to improve the individual behaviors of each character, not only for the AI that was playing against the player but also for the AI that was playing alongside the player. Once again, Finite State Machines made up a crucial part of Artificial Intelligence, but the special touch that helped to create a realistic approach in the sports genre was the anticipation and awareness used in stealth games. The computer needed to calculate what the player was doing, where the ball was going, and coordinate all of that, as well as give a false impression of a team mindset toward the same plan. Combining the new features used in the new genre of stealth games with a vast number of characters on the same screen, it was possible to innovate the sports genre by creating a sports simulation type of game, which has gained so much popularity over the years. This helps us to understand that we can use almost the same methods for any type of game, even if it looks completely different; the core principles that we saw in the computer that played chess is still valuable to the sports game released 30 years later.

Let's move on to our last example, which also has great value in terms of how an AI character should behave to make it more realistic: the game is F.E.A.R., developed by Monolith Productions. What made this game so special in terms of Artificial Intelligence was the dialog between the enemy characters. While it wasn't an improvement from a technical point of view, it was definitely something that helped to showcase all of the development work that was put into the characters' AI, and this is so crucial because if the AI doesn't say it, it didn't happen. This is an important factor to take into consideration while creating a realistic AI character, giving the illusion that it's real; that means the false impression that the computer reacts like humans, and humans interact, so the AI should do the same. Not only did the dialog help to create a human-like atmosphere, it also helped to exhale all of the development put on the character that otherwise the player wouldn't notice was there. When the AI detects the player for the first time, it shouts that it found the player; when the AI loses sight of the player, it expresses that. When the squad of AI's are trying to find the player or ambush him, they speak about that, leaving the player imagining that the enemy is really capable of thinking and planning against him. Why is this so important? Because if we only had numbers and mathematical equations for the characters, they will react that way, without any human features, just math, and to make it look more human, it's necessary to input mistakes, errors, and dialog into the character AI, just to distract the player from the fact that he's playing against a machine.

The history of video game artificial intelligence is still far from perfect, and it's possible that it will take us decades to improve just a little bit more from what we achieved between the early 1950s and this present day, so don't be afraid of exploring what you are about to learn, combine, change, or delete some of the things to find different results, because great games did it in the past and they had a lot of success with it.

Summary

In this chapter, you learned about the impact of AI on the video game history, how everything started from a simple idea to have a computer to compete against humans in traditional games, and how that naturally evolved into the world of video games. You also learned about the challenges and difficulties that were present since the day one, and how coincidentally, programmers kept facing and still face the same problems. In the next chapter, we'll start from that precise point, the most used technique and the technique that caused a lot of debate and evolution that was present on past games as well on present and futures ones.

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
Estimated delivery fee Deliver to Finland

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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 Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Shipping Address

Billing Address

Shipping Methods
Estimated delivery fee Deliver to Finland

Premium delivery 7 - 10 business days

€17.95
(Includes tracking information)

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
Banner background image

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 the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact [email protected] with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at [email protected] using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on [email protected] with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on [email protected] within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on [email protected] who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on [email protected] within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela