Confession time: I went a little overboard and packed way too much into this chapter.
It’s ostensibly about the State design pattern, but I can’t talk about that and games without going into the more fundamental concept of .
That’s a lot to cover, so to keep things as short as possible, the code samples here leave out a few details that you’ll have to fill in on your own.
Don’t feel sad if you’ve never heard of a state machine.
While well known to This pairing echoes the early days of artificial intelligence.
In the ’50s and ’60s, much of AI research was focused on language processing.
In general, a state machine is any device that stores the status of something at a given time and can operate on input to change the status and/or cause an action or output to take place for any given change.
A computer is basically a state machine and each machine instruction is input that changes one or more states and may cause other actions to take place. The read-only memory from which a boot program is loaded stores a state (the boot program itself is an initial state).
The operating system is itself a state and each application that runs begins with some initial state that may change as it begins to handle input.
Thus, at any moment in time, a computer system can be seen as a very complex set of states and each program in it as a state machine.
In practice, however, state machines are used to develop and describe specific device or program interactions.
To summarize it, a state machine can be described as: A finite state machine is one that has a limited or finite number of possible states.