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

Chapter 9
Goal-Driven Agent Behavior
S
o far, we’ve examined agents utilizing a finite state machine-based
architecture where behavior is decomposed into several states, each of
which contains the logic to enable transitions to other states. This chapter
introduces a subtly different approach. Instead of states, an agent’s behav
-
ior is defined as a collection of hierarchical goals.
Goals are either atomic or composite in nature. Atomic goals define a
single task, behavior, or action, such as seek to position or reload weapon,
whereas composite goals are comprised of several subgoals, which in turn
may be either atomic or composite, thereby defining a nested hierarchy.
Composites usually describe more complex tasks than their atomic breth-
ren such as build weapons factory or retreat and find cover. Both types
of goals are able to monitor their status and have the capability to replan if
they fail.
This hierarchical architecture provides the AI programmer with an intu-
itive mechanism for defining agent behavior because it shares many
similarities with the human thought process. Humans select high-level
abstract goals based upon their needs and desires and then recursively
decompose them into a plan of action that can be followed. For instance,
on a rainy day you might decide to visit the cinema. This is an abstract
goal that cannot be acted upon until it’s decomposed into smaller subgoals
such as leave house, travel to cinema, and enter cinema. In turn, each of
these is abstract and must be broken down further. This process is usually
transparent of course, but we occasionally become conscious of it when the
decomposition involves choice. For example, the subgoal travel to cinema
can be satisfied in any number of ways — you may travel there by car,
public transport, cycle, or on foot — and you may find yourself spending a
few moments deliberating your choice. (This is especially true if you are
collaborating with several other humans to satisfy a goal — think back to
the last time you visited a video/DVD rental store with your friends. Argh!)
This process continues until the goals have been decomposed into basic
motor actions your body is able to execute. The leave house goal, for
example, can be broken down into these component goals: walk to closet,
open closet door, remove coat from coat hook, put coat on, walk to
kitchen, put shoes on, open door, walk outside, and so on. Furthermore,
humans don’t like to squander energy so we generally don’t waste precious
379

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