Game Development Reference

In-Depth Information

chapter 3

(FSMs)

Finite state machines are our first formal structure for game AI. The regularity of

the structure helps us to manage program complexity, a major problem of hard-

coded scripts. Using FSMs, we break down the AI into a fixedâ€”hopefully

smallâ€”number of states and the transitions between those states. If you have

studied formal FSMs in classes, our usage may differ. ''It's important to

understand that when game developers speak of
state machines
or
finite state

machines
, they are only loosely referring to the traditional Computer Science

definition.'' [Rabin02]

This chapter looks at what FSMs are and considers their design and analysis. The

analysis includes single-transition review and multiple-transition review.

(Multiple-transition review unearths the problems of ambiguous transitions and

race conditions.) We will touch briefly on complexity and examine three failure

modes. At the end of the chapter are projects to implement an FSM for a game-

related AI.

Finite state machines have a finite number of states and a set of transitions

between those states. So what do we mean by states? The easiest way to think of

states is to think of different ways to finish the statement that begins, ''I am....''

We could create a list of verbs: flying, walking, running, or sitting. Another way

to model uses adjectives: tired, happy, or angry. The set of states might represent

43