-
Notifications
You must be signed in to change notification settings - Fork 17
/
main.py
executable file
·74 lines (53 loc) · 2.35 KB
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#
# This file is part of The Principles of Modern Game AI.
# Copyright (c) 2015, AiGameDev.com KG.
#
import vispy # Main application support.
import window # Terminal input and display.
class HAL9000(object):
def __init__(self, terminal):
"""Constructor for the agent, stores references to systems and initializes internal memory.
"""
self.terminal = terminal
self.location = 'unknown'
def on_input(self, evt):
"""Called when user types anything in the terminal, connected via event.
"""
self.terminal.log("Good morning! This is HAL.", align='right', color='#00805A')
def on_command(self, evt):
"""Called when user types a command starting with `/` also done via events.
"""
if evt.text == 'quit':
vispy.app.quit()
elif evt.text.startswith('relocate'):
self.terminal.log('', align='center', color='#404040')
self.terminal.log('\u2014 Now in the {}. \u2014'.format(evt.text[9:]), align='center', color='#404040')
else:
self.terminal.log('Command `{}` unknown.'.format(evt.text), align='left', color='#ff3000')
self.terminal.log("I'm afraid I can't do that.", align='right', color='#00805A')
def update(self, _):
"""Main update called once per second via the timer.
"""
pass
class Application(object):
def __init__(self):
# Create and open the window for user interaction.
self.window = window.TerminalWindow()
# Print some default lines in the terminal as hints.
self.window.log('Operator started the chat.', align='left', color='#808080')
self.window.log('HAL9000 joined.', align='right', color='#808080')
# Construct and initialize the agent for this simulation.
self.agent = HAL9000(self.window)
# Connect the terminal's existing events.
self.window.events.user_input.connect(self.agent.on_input)
self.window.events.user_command.connect(self.agent.on_command)
def run(self):
timer = vispy.app.Timer(interval=1.0)
timer.connect(self.agent.update)
timer.start()
vispy.app.run()
if __name__ == "__main__":
vispy.set_log_level('WARNING')
vispy.use(app='glfw')
app = Application()
app.run()