spacerose

3.2 готовая

May 19th, 2021
909
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 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.         self.goto_next('roam')
  27.  
  28.     def paint(self):
  29.         self.goto_next('paint')
  30.  
  31.     def join(self):
  32.         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.             print(transition[1])
  39.         else:
  40.             raise RuntimeError('Error!')
  41.  
  42.  
  43. def main():
  44.     o = C32()
  45.     o.paint()
  46.     o.join()
  47.     o.paint()
  48.     o.paint()
  49.     o.join()
  50.     o.join()
  51.     o.roam()
  52.     o.join()
  53.     o.paint()
  54.     o.roam()
  55.  
  56.  
  57. if __name__ == '__main__':
  58.     main()
  59.  
Advertisement
Add Comment
Please, Sign In to add comment