State machine can transform a piece of sequential code into states with flexible transition between states. In a state machine, the code is self-documented and easy to read. In this recipe, we will use the state machine to program a simple rock-paper-scissors game simulator.
To start a state machine, it is a good idea to draw a flowchart first. Start by executing the following steps: