ZiBaT => Peter
Levinsky => IoT=> exercise |
State Machines |
Updated : 2017-02-01
|
Idea: To understand the principles of State Machines and how to program them in Python
Background: previous exercise PWMandGameController.htm and the slides ( pdf | pptx )
Domain: The old fashion snake game.
https://www.youtube.com/watch?v=hAz4bGzXPCc
In the Snake game if the snake is heading south AND you push left the snake will heading east BUT if the snake was heading west and you push left it will heading south.
Set up the states and how the four different input (back, forth, left, right) will change the states and describe the output for each pair of state and input e.g. heading south, right => go west
You can draw a diagram with the states and inputs.
Based on the Paper (see : https://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-01sc-introduction-to-electrical-engineering-and-computer-science-i-spring-2011/unit-1-software-engineering/state-machines/MIT6_01SCS11_chap04.pdf )
Program a Class SM (see paper or slides ) and a new Class SnakeSM to implement the def getNextValues(self, state, inp)
Make a program to try out the SnakeSm by simulating input.
Combine this exercse with the part withthe joystick in previous exercise (see PWMandGameController.htm )