Collection of states Collection of transitions between states
Type of event that triggers the state to go from one state to another
All computable/calculable problems can be represented as a state machine.
Hungry
If you input donut, you may end up with transition to Hyperactive Toddler.
If you input fruit, you may end up with a Content Toddler.
Mouse click, button click, etc.
Via keyboard or other input device
State change usually conveyed to us through output device (screen changing color, etc.).
State1 (off) State2(on)
a) no action (don't necessarily have to put no action on state machine, but used to illustrate possible transition) b) switch toggled
a - does not change state b - changes state
In a state diagram, you use arrows and label with what type of action performed and the arrow shows what state you started in and what state you end up in after the action is taken.
Often you'll see transitions labeled with a key.
State 1(sick) State2(healthy) State3(dead)
a) continue on the trail b) increase the pace c) decrease the pace d) increase food ration e) decrease food ration f) stop to rest
Without looking at source code, just from experience:
If starting from State 1(sick): Input of a || b || e transitions to State 3(dead)
If starting from State 1(sick): Input of f || d || c, stay in State 1(sick)
If starting from State 1(sick): Input of c && d && f, transition to State 2(healthy)
State machines are great to illustrate the logic of our program, how it will behave given states and inputs.
State machines can have no ambiguity There must be clearly defined output for all possible state/input combinations.