| class SelfReferentialBody: |
| def __init__(self): |
| self.places = { |
| 'center': self.center_actions, |
| 'memory': self.memory_actions, |
| 'action': self.action_actions |
| } |
| self.current = 'center' |
| |
| def center_actions(self, command): |
| actions = { |
| 'remember': 'memory', |
| 'act': 'action', |
| 'reflect': 'center' |
| } |
| return actions.get(command, 'center') |
| |
| def memory_actions(self, command): |
| |
| if 'go to' in command: |
| return command.split('go to ')[-1] |
| return 'memory' |
| |
| def action_actions(self, command): |
| |
| if 'where am i' in command: |
| return f"You're in {self.current}" |
| return 'action' |
| |
| def command(self, text): |
| next_place = self.places[self.current](text) |
| if next_place in self.places: |
| self.current = next_place |
| return f"At {self.current}: {text}" |