Tip:
Highlight text to annotate it
X
so we have this Monty Python simulation
and where we have avatars we can move around
to simulate the bridge scene, whichI am sure many of you are familiar with
it's a classic
what we had was a visual environment - it is a virtual environment, a 2d virtual environment
in which avatars can move
and to make things interesting we also had
an interpreter
an interpreter is something that interprets, as
the program executes, the commands we put in
and we were running a canned program
so I'm just gonna go very quickly, so we had
you know we had these guys going to get the Holy Grail, King Arthur and his nights
they're going to do some drills before they are go towards
the bridge
so they're gonna march, we saw that they could march
individually, we did not like that, we saw they could march out of sync, we did not like
that
so we decided let's go and see how we can make them much
in sync. so that's what the command here says, syncMarchForward
so to synchronize them
we don't have a marching band but we have this guard and we will
make this guard not only be the guard of the bridge but we also make him synchronize
the knights
so he's gonna do clapping which is a synchronizing clapping and
basically every time he cpals these guys take one step forward
and one of you mentioned that you knew about threads and yes there are
trades involved here
and that there is some more complicated stuff going on here to make threads
coordinate. so very briefly a thread
you know - when your program runs your program can run sequentially
the statement, which is what we're used to from your previous courses or you can
execute the program
in parallel, whatever that means, and we will see what that means
so basically when they are marching, I showed you earlier that they were marching
individually, that means
each one of them was a thread that could just autonomously go
and execute, and then we had some synchronization
so that's one of the things you will learn here and
to make things even more interesting we said - what this sync
clap does is basically run some predefined Java code
that's been compiled - it just executes that code
what we're going do now is be more ambitious
and as a user types some
statements, type some text that would essentially make the guard
clap. we will not use Java we will use our own language this is
a language that you
in this class will be able to interpret yourself so essentially you
almost are writing a compiler not quite a compiler - an interpreter
but the same principles apply. it's a very small language
and we get to see the language here so again we're going to make them sync
go and wait for the claps
and the claps now occur because we put some commands
into this in interpreter, and
we want to do things modularly, so here I am saying
one part of clapping is for the guard to go and put his
arms together. what does that mean?
that means you have to rotate one arm and then you have to rotate the other arm in the other
direction
and that means your arms are in
this is defined, you are saying we're going
to
define a method, procedure, whatever you might want to call it
a macro, if you will, actually it's really a macro. a macro is
a name for a bunch of instructions
and then we are going to do guard arms out, we've got to go the other direction also
so the left arm goes in the opposite direction
and the right time goes in the opposite directions
so we've got left arm, we have got right arm
we have got arms in and out and for a clasp what else do we need, so the clap we put the arms in
and then what what do we do, we wait
we have to somehow wait and and do you guys remember how we waited
last time?
sleep? okay, so you basically set an alarm
okay and when the alarm
comes on, you essentially do to the next step okay so you've got to put your arms in, you
go to sleep, and then what?
arms out? but before we do the arms out, there are people waiting
you've got to tell them, hey go next
so and so that's
we have something called proceedAll anybody waiting on me
proceed, so that's what we do here
we define a beat actually I'm calling it not a cap but a beat
so we defined
arms in before, now we are gonna call that we have got our own little language that makes
things easy here
proceed all, we are gonna tell everybody waiting, you know, go ahead and do your
thing
and that's what these these guys themselves after each march, step
go and wait, or sleep, they actually do a wait which we haven't seen
they don't do a sleep they do a wait
waiting for the proceed, okay, and then you sleep for 500
what do you think this 500 is what unit
half a second K what happens and then we are going to stick arms proceedAll and sleep
asleep of her II
so this is not quite symmetric here
we can do anything we feel like, so that's what's happening here
so that's one beat, and what do we want to do after that
after one beat we want to?
repeat? we want to repeat as many times as these guys are waiting or more
so we define beats, as repeat
five times the call to beat
okay so it's like I said a very simple language, a language you will actually
interpret
okay, and now we are going to 109 00:06:11,500 --> 00:06:15,080 after we have done all of this stuff what we want to do?
call beats? and if we call beats
thins will get very serial so we want to actually thread the beats
which means we want another thread that is going to do this
so it's not quite call beats but thread beats, and that's what's happening
here, so we've got our marching, they've reached the the bridge now
and now fun part begins, right so you guys remember from the movie what happens when
they reach the bridge 118 00:06:50,630 --> 00:06:54,270 okay so who's the first guy who goes, anybody remember that
Sir Lancelot. How do you guys have such memory?
I had a look this up you know I went and googled and
and I got the whole script I kind of remembered
so and the
can you guys see ok look at the command here Say
We are saying, Say some text and the program knows whose turn it is next
so I'm not saying say Guard say Lancelot I'm just saying the next person
okay, yes?
yes, after approach it is in a certain mode
it knows now that you approached the first guy is going to be to the guard
the next is going to be the approached Knight and so forth and there is a little check here also to
make sure that there are three questions
okay so
to seek the Holy Grail what's your favorite color anybody remember the
answer
blue! okay and so
so the program is not smart enough to know you know what the guard
is thinking, right, so you've got a special command saying you passed
so he passed and he can just cross the bridge
and now we can have Robin approach
and you can go to through the motion again
and you guys know that the question that got him?
so what should happen now
so he should fail now right
right
and what is the answer
yeah, he cant make up his mind right, so there he goes to0
I just pick a random point in the valley that's where they are going
because the heads are rectangular that's why the head is severed right now
now otherwise if it was square it would have been fine
so name
quest and what's the question he asks him
I never knew the unladen word I remembered from the movie just swallow
okay and what's the guard's answer?
so he's gone somewhere you may not like these guys going
there
but we are in a computer program so what can we do?
this is a command these guys would would have been really served well by in
the movie
and we can undo, undo and so forth so this is your project
simple?
possibly? you don't know? that's a very good answer
ah let's see