Home‎ > ‎CIS 98‎ > ‎

Lab 9: Programming with Loops and Decisions

In this lab you will write a loop to make Frodo run a maze.


The purpose of this lab is to write a generalized program that will allow Frodo to run the perimeter of his world regardless of its shape and find his way out of a maze. You will see that the second program also solves the first. 

Programming Assignment

In an attempt to make Frodo more aware of his environment, two cameras are installed on his helmet. These cameras allow him to tell if the way is clear to his right and to his left. The instruction to utilize the right-facing camera is:

is_clear RIGHT

and the instruction to utilize the left-facing camera is:

is_clear LEFT

These two arguments to the is_clear command will prove very useful to you in these exercises. 

Part 1: Improved Perimeter Run

Frodo must now run a lap around Middle Earth which has become irregularly shaped due to various subdivisions and construction projects. It can no longer be assumed that Middle Earth is square, so you need to write a generalized program that will insure that Frodo traverses the perimeter of his world and that he stops on the origin. Note that he has a single ring in his ring-bearing bag that he can use to mark the origin from which he starts. Use map9.1 for this exercise.

frodo -m map9.1

Part 2: Escape Mordor  

Write an instruction named follow_wall_right, assuming that whenever Frodo executes this instruction there is a wall directly to his right. The figure below shows all three of the different position changes that he must be able to make. Your follow_wall_rught instruction should move Frodo one block only, and that move must be such that the wall remains on his right side. This instruction is the cornerstone for a program that directs Frodo to escape from a Mordorian Maze - map9.3 and map9.3a.

 Before  After 

Having written this function, you can use it to make Frodo escape from the maze in map9.3 You also have map9.2 which can be used to test your follow_wall_right() function. 

Turn In 

In a directory called lab9 copy your two scripts:
  • prog9.1 (the perimeter run), 
  • prog9.2 (Getting Frodo through the maze). 


  • 10 points for prog9.1
  • 10 points for prog9.2