0% found this document useful (0 votes)
648 views5 pages

Alice Project (Shell Game)

The document describes instructions for recreating a shell game animation in Alice. It involves lowering three teacups onto a table, one at a time, with a ball hidden under the middle cup. The player is then instructed to guess which cup the ball is under after the cups are shuffled around randomly. The steps include: displaying instructions, lowering the cups, attaching the ball to the middle cup, writing a method to shuffle two cups, revealing the contents at the end by raising the cups, adding variability to the shuffling direction and randomly shuffling cup pairs between 20-30 times.

Uploaded by

Jason
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
648 views5 pages

Alice Project (Shell Game)

The document describes instructions for recreating a shell game animation in Alice. It involves lowering three teacups onto a table, one at a time, with a ball hidden under the middle cup. The player is then instructed to guess which cup the ball is under after the cups are shuffled around randomly. The steps include: displaying instructions, lowering the cups, attaching the ball to the middle cup, writing a method to shuffle two cups, revealing the contents at the end by raising the cups, adding variability to the shuffling direction and randomly shuffling cup pairs between 20-30 times.

Uploaded by

Jason
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Animation and Game Design - Alice 01-06 PJ Project 1.

02 (Shell Game)
Shell Game: Download, extract, and save the provided Alice project named Shell Game. When opened, a
table, three teacups, and a white ball are immediately visible (among other objects). The teacups are suspended
in a line upside down above tabletop and are positioned exactly one meter apart from their nearest neighbor.
Your assignment is to recreate a version of the ancient Shell Game, where a ball is hidden under a cup, and the
cups are then shuffled around each other several times. When the cups stop moving, the player (you) tries to
guess under which cup the ball is located.

This is a complex assignment with many parts to it. The more parts you are able to complete, the more points
you will receive. Please follow the instructions carefully, so your work will not be any more difficult than it
needs to be.
Step 0: Start by displaying a message above the teacups such as the one in the illustration above. There is a
textModel object already provided in the scene. Just call the setValue method of the textModel object,
and add the text that you want printed. You may want to set a time delay of about 2 seconds so things dont
move along too fast.
Then, write instructions that lower each cup (one at a time) straight down onto the top of the table. Remember
that the cups are upside down, so their orientation is upside down as well. They should move down a fixed
amount (youll have to figure out how much) until they are on top of the table.
Perhaps you already know this, but objects in Alice have a vehicle property that allows one object to be carried
by another object. Basically it will glue one object to another so that wherever the vehicle object moves, the
other object will move with it (but not vice-versa). In other words, if there was a Person object and a Car object,
and for the Person we setVehicle to the Car, then wherever the Car goes, so will the Person (but if you move the
Person, the Car will not follow).
We want the middle cup (teacup1) to be the vehicle for the ball so that the ball will stick with the cup
wherever it goes. To do this for the ball object, call the setVehicle method and set it to teacup1, as
shown in the image below. Do this after the cup has moved down on the table and is covering up the ball.

When you have finished this first step and then run your program, descriptive text should appear above the
cups, and then (after a brief pause), each cup will descend to the top of the table one at a time.

Step 1: Write a procedural method named shuffle for the Scene class. This method is intended to

shuffle two cups so that the two cups exchange positions. For example, if teacup0 exchanged with
teacup1, then after the shuffle teacup0 would now located where teacup1 was originally located,
and vice versa. Note that if we move the cup with the ball under it, the ball will move with the cup
because the cup is the balls vehicle. When the shuffle method executes, the cups should appear to
slide horizontally on top of the table to give the illusion that the ball is trapped underneath one of
them.
There are three object markers already placed in the scene for you to use. These object markers are
invisible when you run your code, but they are visible in the scene editor. Object markers can be used
as an invisible reference point, and in this case, we want to use them as a pivot point to rotate (slide)
the cups around in a circle. The object marker on the left is called leftSidePivot, is colored red,
and is located exactly halfway between the two cups on the left. The object marker on the right is
called rightSidePivot, is colored green, and is located exactly halfway between the two cups on
the right. The object marker in the middle is called centerPivot, is colored white, and is located
exactly under the center of the middle cup. You will be able to see all three of these object markers
when you are in the scene editor, but not when you run your code.
The shuffle procedure method must have three parameters: a teacup, a second teacup, and an object
marker around which the cups are to rotate. When you write the method, you should presume that
the object marker will be exactly in the middle between the two teacups. Then all you have to do is
turn both cups one-half turn in the same direction as seen by the object marker. When finished, the
method should look something like the following.

Then you can test your shuffle method by inserting something like the following in myFirstMethod.

If everything is working correctly, when you run your code, you should see the two cups on the left
exchange places.
Step 2: Write the routine for revealing the contents of the cups at the end of the game. Start by
changing the text message on the screen to read Which cup is the ball under? This can be done in the
same manner as you did in the very beginning (by calling the setValue method of the textModel
object).
Next we need to release the ball from the cup, by setting the balls vehicle property to something else
(i.e. the table). The statement looks something like the image at
the right.
Lastly raise up each of the cups, one-at-a-time, with the cup holding the ball being the last one to rise.
As the ball started out under teacup1 (whichever one that is), it will still be under teacup1, so

teacup1 should be the last one to rise up above the table. You can build the drama of the game by
delaying the reveal by several seconds so that the player has a moment to decide which cup hold the
ball.
When you have finished this step, and then run your code, the animation should show the cups
descending, the two cups on the left side swapping places, and then the cups rising up again (with the
ball left on top of the table).
Step 3: Add some variability to the direction the cups rotate in the shuffle method. In other words,
the animation would look better if the cups did not always rotate in the same direction. Alice has a
means to randomly flip a coin and then choose a course of action based on the result (either heads or
tails). To do so, create an if branching structure in the shuffle method (just select true for now).
Then click on the true value in the header, and from the
dropdown list select nextRandomBoolean (a Boolean value
is either true or false). Now Alice will randomly select either
one of the if branches. Your if branching structure should
look something like the image on the right.
Lastly, its kind of a dead giveaway that a cup has been moved if its handle is in a different position. All
of the cups start with their handles facing towards you. Keep them facing towards you at all times by
rotating each cup a half circle normally around its own center at the same time and in the same
direction as you rotate the cup around the pivot point.
Now when you test your shuffle method, the cups should randomly rotate either to the right or left,
and the cup handles should remain facing towards you.
Step 4: Randomly pick two cups and a pivot point to shuffle, and then loop this behavior so that it is
performed randomly somewhere between 20 and 30 times. In other words, your code will randomly
pick 2 cups to shuffle at least 20 (but not more than 30) times.
This is the most challenging logic of the assignment. We need to build a branching structure that
randomly picks a pivot point (one of the three), and then the appropriate two cups to be rotated
around that pivot point, and then pass all three of these objects to the shuffle method. On top of
this, the whole thing needs to be put in a random count loop, so the shuffle method will be called
between 20 and 30 times. Here are the instructions on how to do so.
Lets start by looking at our possibilities of which cups can be shuffled. There are only three choices,
exchange the two cups on the left, exchange the two cups on the right, or exchange the two cups on the
outside. That means we want to pick either the two cups nearest the leftSidePivot, or else the
two cups nearest the rightSidePivot, or else the two outside cups and the centerPivot. If we
could make one of those three choices randomly, then all youd have to do is call the shuffle method
with the chosen two cups and pivot point as parameters. Repeat the procedure some 20 to 30 times
and youve got it all.
So how can build a structure that will
randomly choose one of three options? One
way to do so is to build two if branching
structures, one inside the other, so that it
looks something like the image on the right.

Now granted, in all probability the first choice will be selected about half of the time, and the second
two choices each about a quarter of the time, but thats acceptable for our needs. (There are other
more complex ways in Alice to even out the probabilities, but I leave that for you to figure out if you
are interested.) So in other words, about half of the time the two outside cups will get shuffled, and a
quarter of the time the two cups on the left side will get shuffled, and a quarter of the time the two
cups on the right side will get shuffled.
Given that we now have chosen which pivot point we are going to use (center, left, or right), we now
need to pick the appropriate cups to rotate around that pivot point. Bear in mind that at this point in
time, we dont know which cup is in what position on the table. Given a pivot point, well have to
figure out which cups are the appropriate ones to shuffle. Picking two cups of three possible choices
involves another three way selection. In other words, the appropriate two cups are one of the
following three pairs, either teacup0 and teacup1, or else teacup1 and teacup2, or else
teacup0 and teacup2. Next we are going to figure out which one of these pairs are the right ones to
rotate based on their distance from the pivot point.
If we are rotating around the center pivot point, then the cup we dont want is the one in the center
(right on top of the center pivot point). All we have to do is find the cup in the center, and then we
know to shuffle the other two cups. To find the center cup, well pick a cup and see if it is very close to
the center pivot point (say less than 0.25 meters just in case the center cup is a little bit off center). At
most well only have to test two teacups to see if it is the center. If the first cup is in the center, then
shuffle the other two, and youre done. If not, then see if the second cup is in the center. If the second
cup is in the center, then shuffle
the other two, and youre done. If
neither the first nor the second
cup are in the center, then it must
be that the third cup is in the
center (dont you love how logic
works?), so shuffle the other two,
and youre done. The program
logic should look something like
the image on the right. Of course
you will have to add the
appropriate calls to the shuffle
method to make it all work properly.
If we are rotating around the left side pivot point, then the cup we dont want is the one that is the
furthest away from that pivot point. All we have to do is find the cup that is more than a meter away
from the pivot point, and then
we know to shuffle the other
two cups. This routine is very
similar to the one you just did,
only we want to find the cup
that is more than a meter away.
Again, we only need to test at
the most two cups. The logic
should look something like the
image at the right.
Lastly, if we are rotating around

the right side pivot, we are doing the same thing we just did, except for checking for the right side
pivot instead of the left. Can you figure out the logic statements for the right side all by yourself?
Now all you need to do is to put this entire branching logic in a count controlled loop that will execute
it somewhere between 20 and 30 times. Start by putting everything in a regular loop that will execute
a specific number of times (say 3). Then click on the 3, and look for the word Random in the drop
down message box. Click on Random, and then
nextRandomIntegerFromAupToButExcludingB, and then enter the integers 20 and 30. This
will make a count loop that will execute between 15 and 30 times (what we want). The entire count
loop should look something like the following (except that the shuffle method calls are missing).

Congratulations. Your project should now be completed. Be sure to test it thoroughly to make sure it
is working properly, and then demonstrate your work for me to see. Make sure that you have detailed
comments for each section of your code.

You might also like