CS320n - Assignment 5
Placed online: Monday, March 9
Due: No later than 11:00 pm, Wednesday, March 25
Value: 30 points. ~4% of final grade
Purpose: To create a program that uses loops.
You may either work with one other student in the course, or work alone.
Complete the following world.
Requirements:
The name of your world shall be your UTEID followed by a dash and a5. For example, my UTEID is scottmd3 so my world would be named scottmd3-a5.a2w.
Create an animation (not an interactive program) that shows a kangaroo searching for food.
Download the world
TheSearchForFoodHomework5.a2w. (Note
some web browsers changes the file extension of Alice worlds to .zip when you download
them. If this happens simply rename the file with the .a2w
extension. Also, you cannot open Alice worlds by double clicking on them. You
must start Alice and then open the world from within Alice.) This has the
initial set up for the world. A kangaroo is positioned in a grass world with
three flowers.
The kangaroo is hungry but has poor eyesight. It can't see the
flowers. The kangaroo starts a search for the food. To look for food the
kangaroo performs a box search. It hops forward 1 hop, (which moves it forward
a total of 1 meter), turns left 1/4 of a revolution and hops forward 2 hops.
(Moving it forward a total of 2 meters.). It continues to turn left a quarter
of a revolution and hop one more hop than the previous leg. The pattern causes
the kangaroo to max a boxy spiral as shown below:
Please note the following are not exact step by step instructions on how to
complete the program. They are tips, not a cookbook. You will have to step
outside the instructions at times and think about how to solve the problem
based on the things you have learned in class and on other assignments.
Make a realistic hop method for the kangaroo. Call this method repeatable so the kangaroo moves in the box search pattern.
In order to move the correct number of hops on each leg you
will find it useful to have a number variable. After completing a leg set the
value of the variable equal to the variable plus 1. Do this by dragging the
variable into the program, picking the "set value" option, picking
expressions, and then picking num Hops. After use the triangle to perform math
and set the value to num Hops + 1
After setting the value to num Hops select the the triangle to perform math and set the value to num Hops + 1
The final set value command should look like this.
After each single hop, if the kangaroo is within 1.5 meters of
any of the three flowers it turns towards that flower hops to it, eats the
flower, turns around, hops back to its position in that leg of the search, and
then turns to face the way it was going in that leg. The last part of this behavior,
getting the kangaroo to move back to its original behavior is tricky because
it is not trivial to determine how many revolutions the kangaroo turned to
face the flower. A clever way to handle this is to create another object that
moves lock step with the kangaroo. It moves forward and turns the same amount
as the kangaroo, but it is invisible. When the kangaroo has moved back to the
invisible object use the orient to method to get the kangaroo to turn
back to the correct facing.
The image below is suppose to illustrate this behavior. During the leg with 6
hops on the bottom the kangaroo is close enough to smell the flower at the
point with the orange arrows. She turns to face the flower, hops once to
it, eats it, turns to face the position she was at in the leg, hops back and
then turns to continue that leg.
The kangaroo should continue this pattern of movement until all three flowers have been eaten. After eating the last flower the kangaroo should finish the leg it is on.
Hints:
You should use a loop (definite loop) to move the correct number of hops. The limit of the loop should be the num Hops variable.
You should use a while loop (indefinite loop) to check if the kangaroo is within has finished eating all 3 flowers.
Create class and world level methods and functions to break the program up into understandable pieces.
Be sure to save your world and rename the file with your UTEID and -a5.
Turning in your assignment. The assignment must be turned in no later than 11 pm on Wednesday, March 25. To turn in your assignment you must have your Microlab account id and password. Use these to turn in the program electronically using the Microlab turnin web page. Refer to this web page for instructions on using the turnin web page