Game Development Reference
In-Depth Information
operation, but it may present problems after the data upon which it depends
works through the range of possible values. The questions to ask are ''Is this
transition reasonable from this state in the first place?'' and ''Is this transition still
reasonable when the machine returns to this state from other states?''
Multiple-Transition Review
The second thing to review is multiple transitions. When there is more than one
transition out of a state, we face two related issues: disambiguation and race
conditions. If two transitions from a single state can be valid at the same time,
they are ambiguous. One way that transitions can become ambiguous is if more
than one thing in the game world can change before the AI runs again. This gives
rise to race conditions. If only one thing can change at a time, Figure 3.2 is
perfectly fine. A monster that is in the Attack state can run low on health or it
can run out of players, but as long as they do not happen at the same time, the
monster AI always does the right thing. If both of those events can happen at
the same time, however, the monster AI FSM has two valid transitions to pick
from. Transitioning to the Hiding state makes sense, but going to the Flee state
does not. The Flee state would transition to the Hiding state as soon as it got a
chance.
The problem is that our monster is fleeing from enemies who are not there. A
similar condition exists when a monster in the Flee state is healed (perhaps by a
more powerful allied monster) at the same time that the players stop pursuit and
make themselves scarce (perhaps in order to avoid having to deal with two
monsters at the same time). In this case, the FSM in Figure 3.2 will have our
monster attack players who are not there. Race conditions like these tend to be
subtle and hard to detect at first glance.
In real game development, the AI programmer cannot require that the system
change only one thing at a time in order to prevent race conditions in the AI; the
AI programmer is forced to deal with race conditions as a fact of life. There are
three ways to handle race conditions and ambiguities. You can ignore them, you
can fully specify all transitions, and you can prioritize the transitions.
The easiest way to handle ambiguities is to simply not care. In the FSM shown in
Figure 3.2, it could be argued that no player will ever see the monster being
stupid. The ambiguities all happen when there are no players and some other
condition also changes at the same time. We have already noted that if the player
never sees great AI, that AI is wasted. Conversely, and to our benefit, if the
 
 
Search Nedrilad ::




Custom Search