Summary
By completing this chapter, you now have a maintainable, extendable system for creating behavior in AI agents. Continue to play around with the FSM, create new states, and combine them in different ways to create complex behavior. You could even revisit previous projects and extend existing functionality using an FSM—for example, the quest-giving NPC in Chapter 6, Continuing the 2D Adventure, could have a movement state and a talking-to-player state. Also, the FSM doesn't just have to be used for AI. For any system that has distinct and separate states, it's worth considering an FSM.
Although the FSM is versatile, it has a somewhat rigid structure. We can calculate what the chick will do every step of the way because we've hardcoded its behavior, which is ideal in many instances but has a few drawbacks. Firstly, there's no opportunity for emergent behavior. Any behavior we want our chick to act out needs to be explicitly programmed. The chick will...