CSCI 170 (GOLDWEBER)
Spring 08: 1/24/08
Homework 1: A Sample Program
To aid you in completing Homework 1, you can study the solution to the following problem as an example to follow:
Consider the problem of Karel getting a summer job setting up pins for a bowling alley. Hence the problem is to program Karel, starting from the origin facing East (denoted as (1, 1 East)) to set up 10 beepers in a standard 10-pin bowling pattern. The "head" pin is to be located at (6,2). After setting up all the pins, Karel moves out of the way to (6, 6, South) prior to turning off.
Please study the
two
provided solutions to this problem bowling1.rur
and bowling2.rur
. Feel free to download the program and run it in addition to studying it. Remember that Karel must have at least 10 beepers in its pouch at the start. (No special world environment needed.)
Notice the level and depth of the documentation. Also notice that "utility" routines do not need documentation. As one can see at the bottom of the program that all one needs to `do is "run" the algorithm is to issue one command (to do the work) and then turn off. Hence this is a good example of top-down programming.
At the top level is the function: setUpPins
At the middle level of this problem's decomposition are the functions moveToStart, moveOutOfTheWay, moveOutOfTheWay, moveOutOfTheWay, etc.
Finally, at the bottom level are the hardworking utility functions turn_around and turn_right
There is a possible 20 points for this homework.
GOOD LUCK
File translated from
TEX
by
TTH,
version 3.74.
On 29 Jan 2008, 11:49.