-
Notifications
You must be signed in to change notification settings - Fork 0
/
concrete_fsm.py
44 lines (42 loc) · 1.12 KB
/
concrete_fsm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class FiniteStateMachine:
"""
Example of concrete Finite State Machine implementation.
"""
def __init__(self):
self.state = "A"
def tick(self, input):
if self.state == "A":
if input == 0:
self.state = "D"
return 2
elif input == 1:
self.state = "C"
return 0
elif input == 3:
self.state = "B"
return 1
else:
return None
if self.state == "B":
if input == 0:
# Invade bug inside implementation
# self.state = "A"
return 1
else:
return None
elif self.state == "C":
if input == 1:
return 1
else:
return None
elif self.state == "D":
if input == 1:
self.state = "B"
return 0
elif input == 2:
self.state = "A"
return 1
else:
return None
else:
return None