source: scenarios/InTheWild/cmionInTheWild/advert.bsh @ 1530

Revision 1530, 7.7 KB checked in by michael.kriegel, 7 years ago (diff)

updated in the wild scenario code

Line 
1import uk.ac.hw.lirec.dialogsystem.DialogInterface;
2import uk.ac.hw.lirec.dialogsystem.DialogInterface.Moods;
3import uk.ac.hw.lirec.dialogsystem.DialogInterface.Expression;
4import java.util.HashMap;
5import java.text.SimpleDateFormat;
6
7
8
9
10/*
11 * GENERAL HELP
12 * Watch you don't miss a ; off the end of a line, can lead to silent failing to
13 * do anything!
14 */
15
16
17DialogInterface di;
18HashMap migrationData = new HashMap();
19
20greetUser(String name) {
21        di.speakText("Hello there, "+name);
22}
23
24saySomething(String speech) {
25        di.speakText(speech);
26}
27
28startInteraction()
29{
30        Calendar cal = Calendar.getInstance();
31        SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm:ss");
32        di.log("\n" + sdf.format(cal.getTime()));
33        long timeStart = System.currentTimeMillis();
34       
35        di.showExpression(Expression.SURPRISE);
36        di.speakText("Oh. Hi There. I'm an experiment advertising agent.");
37        di.speakText("I'm not as smart as I look but could I still bother you for a second?");
38        String answer = di.multipleChoiceQuestion(2,new String[]{"Yes","No"});
39        if (answer.equals("Yes"))
40        {
41                        di.log(" q1Yes " + (System.currentTimeMillis()-timeStart)/1000);
42                        di.showExpression(Expression.JOY);
43                        di.speakText("Nice, I like you.");
44                        di.speakText("And because I like you I'm going to let you in on a little secret.");
45                        di.speakText("Are you ready for it?");
46                        di.getResponse("Yes");
47                        di.log(" c2 " + (System.currentTimeMillis()-timeStart)/1000);
48                        di.showExpression(Expression.JOY);
49                        di.speakText("See what I did there, didn't really give you a choice. hahaha");
50                        di.speakText("Anyway here's the thing. There's a treasure hidden in this building.");
51                        di.getResponse("Wow, really?");
52                        di.log(" c3 " + (System.currentTimeMillis()-timeStart)/1000);
53                        di.speakText("Yes, amazing isn't it? Do you want to know where it is?");
54                        di.getResponse("Where?");
55                        di.log(" c4 " + (System.currentTimeMillis()-timeStart)/1000);
56                        di.speakText("Slow down, you should know it's a dangerous buisness.");
57                        di.showExpression(Expression.FEAR);
58                        di.speakText("Are you brave enough to risk your life for fame and riches?");
59                        String answer2 = di.multipleChoiceQuestion(2,new String[]{"Yes","No"});
60                        if (answer2.equals("Yes"))
61                        {
62                                di.log(" q5Yes " + (System.currentTimeMillis()-timeStart)/1000);
63                                di.speakText("That's the spirit!");                             
64                        } else
65                        {
66                                di.log(" q5No " + (System.currentTimeMillis()-timeStart)/1000);
67                                di.speakText("I was just joking, of course it's not dangerous. Health and safety regulations, you know.");                             
68                        }                       
69                        di.speakText("So here's how to find the treasure");
70                        di.getResponse("Tell me");
71                        di.log(" c6 " + (System.currentTimeMillis()-timeStart)/1000);
72                        String answer3 = "No";
73                        do
74                        {
75                                di.speakText("My colleagues are recruiting a group of treasure hunters like yourself.");
76                                di.speakText("Just write your email adress on the sheet below and they will be in touch with you.");
77                                di.speakText("Got that?");
78                                answer3 = di.multipleChoiceQuestion(2,new String[]{"Yes","No"});
79                                if (answer3.equals("No"))
80                                {       
81                                        di.log(" q7No " + (System.currentTimeMillis()-timeStart)/1000);
82                                        di.speakText("Alright, again, but please pay more attention this time.");
83                                }
84                                else
85                                {
86                                        di.log(" q7Yes " + (System.currentTimeMillis()-timeStart)/1000);
87                                        di.speakText("You're real smart. I'm sure you're going to be the one to find it.");
88                                }
89                        } while (answer3.equals("No"));
90                                di.speakText("Go, get them tiger!");
91                                di.showExpression(Expression.JOY);
92                                Thread.sleep(10000);   
93        }
94        else
95        {
96                di.log(" q1No " + (System.currentTimeMillis()-timeStart)/1000);
97                di.showExpression(Expression.ANGER);
98                di.speakText("Alright, then please leave me alone. ");         
99                Thread.sleep(10000);   
100        }
101}
102
103/*
104 * This shows up an issue in this "single episode" style, perhaps the answer is
105 * to have blocking functions that return values? program/thread control might be a bit odd then...
106 *
107 * need a policy and stick with it (or does it not matter?)
108 *
109 * There's an issue here where getResponse was resulting in a call to evaluate something else
110 * on this script, was calling the same interpreter, when it hadn't finished the previous evaluation...
111 * ...etc. Seems to cause issues. Need to be careful to prevent this (or avoid with new interp instances
112 * but then the issue is might end up with many cos of recursion!)
113 *
114 * To make this work correctly, getResponse should:
115 *      not call the interpreter
116 *      return immediately, (as it's UI stuff).
117 *
118 * THIS IS THE UNUSED APPROACH
119 *
120tellJoke() {
121        System.out.println("tellJoke called");
122        di.speakText("Here's a joke.");
123        di.speakText("knock knock");
124        di.getResponse("Who's there?","jokePart2()");
125}
126
127jokePart2() {
128        di.speakText("Sherwood");
129        di.getResponse("Sherwood who?","jokePart3()");
130}
131
132jokePart3() {
133        di.speakText("sherwood like to meet you!");
134}
135*/
136
137/*
138 * There's a need to be careful with threading, e.g. the below might be acceptable if
139 * this is run in a different thread to UI stuff
140 * This shows how the timing could be played with.
141 */
142
143boolean wait = true;
144
145blockingJoke() {
146        di.speakText("knock knock");
147        di.getResponse("Who's there?");
148        Thread.sleep(3000);
149        di.speakText("Sherwood");
150        //just the first part to test this.
151}
152
153
154
155
156/*
157        Here's a mk2 version, where the "actions" don't result in calls to the interpreter before
158        they return - this is much safer, avoids the issue, but perhaps awkward?
159       
160        This relies on the getresponse calls blocking till the response is given, which they
161        don't, as android's all about asynchronous dialog/ui in general.
162*/
163tellJokeBlocking() {
164        di.speakText("knock knock");
165        di.getResponse("Who's there?");
166        jokePart2();
167}
168
169jokePart2() {
170        di.speakText("Sherwood");
171        di.getResponse("Sherwood who?");
172        jokePart3();
173}
174
175jokePart3() {
176        di.speakText("sherwood like to meet you!");
177}
178
179//of course this can be combined:
180
181combinedJoke() {
182        di.speakText("knock knock");
183        di.getResponse("Who's there?");
184        di.speakText("Sherwood");
185        di.getResponse("Sherwood who?");
186        di.speakText("sherwood like to meet you!");
187}
188
189//some waffle to test interruptions
190waffle() {
191        di.speakText("Cutting edge robot technology is being used to enhance the ancient tradition of whisky barrel cooperage. The hi-tech systems have been installed at a new custom-designed £10m cooperage near Alloa in Clackmannanshire.");
192        di.getResponse("Speech finished?");
193        di.speakText("more waffle waffle waffle waffle waffle.");
194}
195
196int counter = 0;
197boolean yesorno = false;
198
199comeClose() {
200        counter++;
201        if (counter <= 1)
202        {
203                di.showExpression(Expression.SURPRISE);
204                di.speakText("Oh. Hi There. Could I bother you for a second?");
205                String[] options = {"Yes","No"};
206                String answer = di.multipleChoiceQuestion(2,options);
207                if (answer.equals("Yes")) {
208                        yesorno = true;
209                        di.showExpression(Expression.JOY);
210                        di.speakText("Thank you! I'm preparing a treasure hunt in this building.");
211                        di.speakText("Please come and help out.");             
212                } else {
213                        yesorno = false;
214                        di.showExpression(Expression.ANGER);
215                        di.speakText("Alright, I guess you're too busy to talk to a boring robot, eh?");               
216                }
217        } else
218                if (yesorno) di.showExpression(Expression.JOY);
219                else di.showExpression(Expression.ANGER);
220}
221
222migrationOut()
223{
224        di.setEmysInvisible();
225        di.migrateDataOut("target",migrationData);
226}
227
228migrationIn()
229{
230        di.setEmysVisible();
231        testInOutScreen();
232}
233
234startScreenMigrateTest() {
235        migrationData.put("migrationNum","5");
236        //di.speakText("Hello there");
237        di.speakText("This is migration "+migrationData.get("migrationNum") );
238        //di.speakText("Press ready on the phone when you're ready to go.");
239}
240
241testInOutScreen() {
242        //di.speakText("Hello there");
243        Integer num = Integer.parseInt(migrationData.get("migrationNum"));
244        num++;
245        migrationData.put("migrationNum",num.toString());
246        di.speakText("This is migration "+migrationData.get("migrationNum") );
247        //di.speakText("Press ready on the phone when you're ready to go.");
248}
249
Note: See TracBrowser for help on using the repository browser.