Create srcs.py
Browse files
srcs.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class SelfReferentialBody:
|
| 2 |
+
def __init__(self):
|
| 3 |
+
self.places = {
|
| 4 |
+
'center': self.center_actions,
|
| 5 |
+
'memory': self.memory_actions,
|
| 6 |
+
'action': self.action_actions
|
| 7 |
+
}
|
| 8 |
+
self.current = 'center'
|
| 9 |
+
|
| 10 |
+
def center_actions(self, command):
|
| 11 |
+
actions = {
|
| 12 |
+
'remember': 'memory',
|
| 13 |
+
'act': 'action',
|
| 14 |
+
'reflect': 'center'
|
| 15 |
+
}
|
| 16 |
+
return actions.get(command, 'center')
|
| 17 |
+
|
| 18 |
+
def memory_actions(self, command):
|
| 19 |
+
# Can recall and reference other places
|
| 20 |
+
if 'go to' in command:
|
| 21 |
+
return command.split('go to ')[-1]
|
| 22 |
+
return 'memory'
|
| 23 |
+
|
| 24 |
+
def action_actions(self, command):
|
| 25 |
+
# Actions that can reference the system itself
|
| 26 |
+
if 'where am i' in command:
|
| 27 |
+
return f"You're in {self.current}"
|
| 28 |
+
return 'action'
|
| 29 |
+
|
| 30 |
+
def command(self, text):
|
| 31 |
+
next_place = self.places[self.current](text)
|
| 32 |
+
if next_place in self.places:
|
| 33 |
+
self.current = next_place
|
| 34 |
+
return f"At {self.current}: {text}"
|