Game Development Reference
In-Depth Information
For more information about designing FSMs, read the chapter “Fundamental AI
Technologies” in Core Techniques and Algorithms in Game Programming by Daniel
Sánchez-Crespo Dalmau (Dalmau, 2004). Although it is a book on programming
the text is very accessible to non-programmers.
HIERARCHICAL FINITE STATE MACHINES IN GAMES
A hierarchical finite state machine (hFSM) actually consists of several different
FSMs, and the ones higher up in the hierarchy give orders to the ones lower
down—that is, the controlling hFSMs send signals to those lower down in the hier-
archy, ordering them to change states. An artificially intelligent opponent in such a
system chooses a top-level goal, such as “take and hold this hill,” and delegates the
tasks required to achieve the overall goal to subordinate FSMs that further delegate
down to the individual unit level.
This is the way commands move down through a real army. The captain decides that
he needs to take a hill and so delegates different activities to different platoons under
him: providing covering fire, creating a diversion, and so on. If done properly, the
platoons each have a different goal and won't get in each others' way. The sergeant
in each platoon then commands his individual men to achieve the platoon's goal
in the same way that the captain commanded the sergeants. Each of the men then
tries to achieve his own goal by executing the command he has been given. In a
video game, each man has his own FSM that determines his behavior. The FSM reacts
to changing conditions on the battlefield (for example, “The unit I was told to attack
is dead, so I will look for another one to attack”) and also to orders received from
the superior FSM, that is, the sergeant's FSM that governs the platoon as a whole (for
example, “Your mission is accomplished, so cease fire and guard your position”).
The nice thing about hFSMs is that they produce emergent behavior—that is, they
may cause units to behave in ways that are not explicitly programmed into the
rules. hFSMs also allow you to design the AI from the top down, creating large-
scale strategies that are made up of individual smaller-scale strategies. hFSMs are
not restricted to combat, either: You can also use them to achieve economic goals,
directing worker units to produce different resources as needed and telling them to
stop when they've stockpiled enough.
DESIGN RULE Don't Ask AI to Micromanage Troops
You may be tempted to try to create large-scale AI systems that coordinate the movements
of individual units right from the top a sort of micromanagement. Don't do this; the
result will be as unwieldy in your game as it would be in real life if a general tried to tell
each individual soldier what to do. Create intelligent behaviors for each level of the hier-
archy, and intelligent results will emerge.
Search WWH ::




Custom Search