O'Reilly logo

Programming Game AI by Example by Mat Buckland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

return bResult;
}
Making Estimates and Assumptions Work for You
You have probably noticed I’ve used many estimates and assumptions
throughout the calculations described in this chapter. At first, this may
seem like a bad thing because, as programmers, we’re used to making sure
everything works “just so,” like perfect clockwork automatons.
Sometimes, however, it’s beneficial to design your game’s AI in such a
way that it makes occasional mistakes. This, as far as making computer
game AI goes, can be a Good Thing. Why? Because it’s more realistic.
Humans make mistakes and misjudgments all the time, and therefore the
occasional mistake made by the AI makes for a much more entertaining
experience from a human players perspective.
There are two ways of inducing mistakes. The first is to make the AI
“perfect” and dumb it down. The second is to allow “errors” to creep in by
making assumptions or estimates when designing the algorithms the AI
uses. You have seen both of these methods used in Simple Soccer. An
example of the former is when random noise is used to introduce a small
amount of error in direction every time the ball is kicked. An example of
the latter is where circles instead of ellipses are used to describe an oppo-
nent’s intercept range.
When deciding how to create error and uncertainty in your AI, you must
examine each appropriate algorithm carefully. My advice is this: If an algo-
rithm is easy to code and doesn’t require much processor time, do it the
“correct” way, make it perfect, and dumb down to taste. Otherwise, check
if it’s possible to make any assumptions or estimates to help reduce the
complexity of the algorithm. If your algorithm can be simplified in this
way, code it, then make sure you test it thoroughly to ensure the AI per
-
forms satisfactorily.
Summing Up
Simple Soccer demonstrates how team-based AI for a sports game can be
created using only a handful of basic AI techniques. Of course, as it stands,
the behavior is neither particularly sophisticated nor complete. As your
knowledge of AI techniques and experience increase you will see many
areas where the design of Simple Soccer can be improved or added to. For
starters, though, you might like to try your hand at some of the following
practice exercises.
Sports Simulation — Simple Soccer | 189
Making Estimates and Assumptions Work for You

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required