Home‎ > ‎CIS 98‎ > ‎

Lab 7: Flow Control

The purpose of this lab is to program Frodo, an imaginary robotic Hobbit with a limited instruction set, to perform more tasks requiring sensing his environment. In this lab you have all of Frodo's instructions to work with. You will need to use the instructions that sense Frodo's environment so that you can make decisions.

Starter Code 

In this lab your code will run in a loop. We'll talk about loops in a few weeks. Each of your programs must begin with the code below: 

# This is a Frodo program

while true; do
  # Your code goes inside this loop.
  # After the "do" but before the "done"

Your Frodo program must make a decision each time through the loop using an if statement. You must also decide when Frodo is done with the program by running the "stop" instruction.  

Run a Lab of Any Size

Using the starter code write a lap program so that the size of the track is not limited to the perimeter of Middle Earth. By setting up blocks I could make the lap smaller or by extending Middle Earth, larger. Your new program should allow Frodo to run around the following course as well as the full course.

$ frodo -m map7.1

Test your program with map7.0.

Gather All the Rings

Now that that Frodo can run a lap of any size, modify the prog7.1 program so that it will pick up any rings that he finds along the way. Each block that he traverses may have no rings, 1 ring or several rings on it. Frodo must gather up all the rings, return to the origin and stop.

$ frodo -m map7.2

Your prog7.1 program must complete both the "Run a Lap of any Size" and the "Gather all the Rings" tasks. Do not create separate programs.


Frodo is faced with running a hurdle race. To win the race, he must scale each hurdle, one at a time, and must not jump when there is no hurdle in his way. He must not shut himself off until he reaches the column containing the ring. You may assume that the hurdles are 1 block high, but you cannot assume how many hurdles there are. Of course there must be less than 10.

$ frodo -m map7.3

Test your program with map7.3a and map7.3b.

Save your program in prog7.3

Turn In

When you are done with your programs, copy prog7.1 and prog7.3 to a directory called lab7 in your home directory. Do not submit a prog7.2 it won't be graded. Your prog7.1 should accomplish both of the first two parts.

Grading Rubric

  • 10 points for prog7.1
  • 10 points for prog7.3