We discussed FSM in Chapter 2, Finite State Machines, using both simple switch statements and the FSM framework. The decision to choose which state to execute was purely based on the true or false value of a given condition. Cast your mind back to the following FSM of our AI-controlled tank entity:
To make the AI more interesting, and a little bit unpredictable, we can give our tank entity some options to choose from, instead of doing the same thing whenever a certain condition is met. For example, in our earlier FSM, our AI tank would always chase the player tank once the player was in its line of sight. Instead, we can split the player on sight transaction in order to connect a new state, Flee. How can the AI decide which state to move to? Randomly, of course:
As shown in the preceding diagram, instead of chasing every...