state machines are typically used for problems where there is some stream of input and the activity that needs to be done at a given moment depends the last elements seen in that stream at that point.
Examples of this stream of input: some text file in the case of parsing, a string for regular expressions, events such as
Examples of activities: be ready to read a number (after another number followed by a
Examples of this stream of input: some text file in the case of parsing, a string for regular expressions, events such as
player entered room
for game AI, etc.Examples of activities: be ready to read a number (after another number followed by a
+
have appear in the input in a parser for a calculator), turn around (after player approached and then sneezed), perform jumping kick (after player pressed left, left, right, up, up).
When your logic must contain information about what happened the last time it was run, it must contain state.
So a state machine is simply any code that remembers (or acts on) information that can only be gained by understanding what happened before.
Read full article from algorithm - What kind of problems are state machines good for? - Stack Overflow
No comments:
Post a Comment