forked from jacnel/LilyInteractive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzoo_actions.py
151 lines (134 loc) · 5.23 KB
/
zoo_actions.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import random
from speech_recog import get_input
from text_to_speech import speak, wrap_text, englishify
from parsers import parse, get_intent
# from run_gif import *
WKSPACE_ID = "353e9ff8-49d9-4f7e-b3ba-7d9eda2702ea"
def entrance(name, remaining):
"""Greeting node
"""
text = "Hi %s. Welcome to the San Diego Zoo! " % name
text += "We have a bunch of great exhibits for you today. "
text += "Say the name of the animal you want to see to go there. "
text += "If you want to leave at any time, just say so. "
text += "We can go see the " + englishify(remaining, conj=False) + ". "
text += "Where should we start?"
text = wrap_text(text, "GoodNews")
speak(text)
def wallet():
"""Forgot your wallet
"""
text = "Oh no! You forgot your wallet! We need to go back and get it. "
text = wrap_text(text)
speak(text)
def parking_lot():
text = "You've reached the parking lot. "
if random.random() < 0.25:
text += "Oh no! Some monkeys escaped. "
text += "They have gotten into your car! "
# runGif("ZooGifs/monkey_steals_wheel_cover.gif")
text += "Those thieves got away! "
text += "We get new exhibits often, so come back soon to see something new. "
text = wrap_text(text)
speak(text)
def monkeys(remaining):
speak(wrap_text("Look at the cute monkeys!", "GoodNews"))
# runGif("ZooGifs/monkey.gif")
text = "Where to now? "
text += update_remaining(remaining, 'monkeys')
speak(wrap_text(text, "GoodNews"))
def elephants(name, remaining):
speak("Elephants are my favorite! Check out its cool painting.")
# runGif("ZooGifs/GIF-Elephant-painting.gif")
text = "What's next, " + name + "? "
text += update_remaining(remaining, 'elephants')
speak(wrap_text(text, "GoodNews"))
def lions(remaining):
speak(wrap_text("Look, that lion must be hungry.", "GoodNews"))
# runGif("ZooGifs/lion_tries_to_grab_baby.gif")
text = "Where would you like to go now? "
text += update_remaining(remaining, 'lions')
speak(wrap_text(text, 'GoodNews'))
def penguins(remaining):
text = "That penguin is a jokester. " # TODO: jokester is mispronounced
# runGif("ZooGifs/penguin.gif")
x = random.random()
if x < 0.75:
text += "Great timing. They are feeding the penguins. "
text += "Should we stay and watch? "
speak(wrap_text(text, 'GoodNews'))
watch("ZooGifs/penguin_feeding.gif")
text = "Which animal do you want to see now? "
else:
text += "Which animal do you want to see now? "
text += update_remaining(remaining, 'penguins')
speak(wrap_text(text, 'GoodNews'))
def tigers(remaining):
text = "Look at that bird flying into the tiger enclosure. "
# runGif("ZooGifs/tiger_and_bird.gif")
x = random.random()
if x < 0.5:
text += "There are baby tigers too! "
text += "Do you want to look? "
speak(wrap_text(text, 'GoodNews'))
watch("ZooGifs/baby_tiger.gif")
text = "What exhibit should we go to from here? "
else:
text += "What exhibit should we go to from here? "
text += update_remaining(remaining, 'tigers')
speak(wrap_text(text, 'GoodNews'))
def otters(remaining):
text = "Check it out - there are otters playing basketball! "
# runGif("ZooGifs/otter_basketball.gif")
x = random.random()
if x < 0.4:
text += "Look! There is a special great white shark exhibit! "
text += "Do you want to stop? "
speak(wrap_text(text, 'GoodNews'))
watch("ZooGifs/white_shark_feeding.gif")
text = "Which animal do you want to see next? "
else:
text += "Which animal do you want to see next? "
text += update_remaining(remaining, 'otters')
speak(wrap_text(text, 'GoodNews'))
def pandas(name, remaining):
text = "Look at all of the silly pandas! "
# runGif("ZooGifs/pandas.gif")
text += "Where do you want to go now %s? " % name
text += update_remaining(remaining, 'pandas')
speak(wrap_text(text, 'GoodNews'))
def update_remaining(l, f_name):
"""Given a list `l` of remaining exhibits and the name `f_name` of the function
calling this function, update `l` by removing the function whose name is `f_name`
and return a corresponding prompt
"""
for i, exhibit in enumerate(l):
if exhibit == f_name:
l.pop(i)
if l:
prompts = ["We haven't seen the %s yet." % englishify(l, conj=False),
"We still have to see the %s." % englishify(l)]
else:
prompts = ["We've seen everything, but you're welcome to go back to any exhibit"]
return random.choice(prompts)
def watch(f):
"""Ask whether the use wants to stay and watch. If yes, play the gif at `f`,
else do nothing
"""
while True:
inp = get_input()
resp = parse(inp, WKSPACE_ID)
intent = get_intent(resp)
if intent == 'watch':
print('watching %s' % f) # TODO: TEMPORARY
# runGif(f)
return
elif intent == 'no_watch':
return
else:
msg = "I'm sorry I don't understand what you said. Could you rephrase?"
speak(wrap_text(msg, 'Apology'))
def main():
otters([])
if __name__ == '__main__':
main()