spacerose

3_2

Jun 2nd, 2021
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 KB | None | 0 0
  1. class C32:
  2.     def __init__(self):
  3.         self.state = 'A'
  4.         self.transitions = {
  5.             'A': {'paint': ('B', 0)},
  6.             'B': {
  7.                 'paint': ('F', 2),
  8.                 'join': ('C', 1),
  9.             },
  10.             'C': {
  11.                 'paint': ('A', 4),
  12.                 'join': ('D', 3),
  13.             },
  14.             'D': {
  15.                 'roam': ('D', 6),
  16.                 'join': ('E', 5)
  17.             },
  18.             'E': {
  19.                 'roam': ('F', 7),
  20.                 'paint': ('E', 8)
  21.             },
  22.             'F': {}
  23.         }
  24.  
  25.     def roam(self):
  26.         return self.goto_next('roam')
  27.  
  28.     def paint(self):
  29.         return self.goto_next('paint')
  30.  
  31.     def join(self):
  32.         return self.goto_next('join')
  33.  
  34.     def goto_next(self, command):
  35.         transition = self.transitions[self.state].get(command, None)
  36.         if transition is not None:
  37.             self.state = transition[0]
  38.             return transition[1]
  39.         else:
  40.             return None
Advertisement
Add Comment
Please, Sign In to add comment