Home‎ > ‎CIS 98‎ > ‎

Lab 2: Introduction to Middle Earth

Problem Set

There are four exercises in the problem set; you will be creating a file for each program. Please name your files prog2.1, prog2.2... up to prog2.4
These five files should end up in a subdirectory of your home directory, called lab2.

Problem 1

Every morning Frodo is awakened in bed when his newspaper, which looks like a ring, is thrown onto the front porch of his Hobbit home. Write a program that will instruct Frodo to retrieve his paper and bring it back to bed with him. The initial situation is shown on the right, and the final situation must have Frodo back in bed (same corner, same direction) with the newspaper. You may use only the following primitive instructions:
  • move
  • turnright
  • pickring
  • putring
  • stop
Name your program prog2.1. You can test your program by running the command:

$ frodo -m map1.2 prog2.1 

Problem 2

The wall sections in the figure below represent Mt. Doom (north is up). Program Frodo to climb the mountain and leave the ring he is carrying at the summit. Frodo must then descend the other side of the mountain. Remember that Frodo is a mere hobbit, he does not have super powers enabling him to leap to the summit in a single bound; he must follow the contour of the mountain on the way up and on the way down.

User Defined Functions

You can extend the simple Frodo actions with actions of your own design. For example, here's how to define a turnleft command:

# Define your own functions at the top of your program. 
turnleft() {

# Now Frodo can use your functions. 

Write your program to climb Mt. Doom using at least one user-defined command (you can use anyone you like). Name your program prog2.2. You can test your program with the command:

$ frodo -m map1.3 prog2.2 

Problem 3

Write appropriate definitions for the following new instructions:
  1. turnaround. Turns Frodo around 180 degrees
  2. backup. Moves Frodo one block backward but leaves him facing the same direction
  3. movemile. Moves Frodo ten blocks in the direction he is facing
Use these three instructions to write a program of your choosing using the default map file. Name your program prog2.3. Test your program with the command:

$ frodo prog2.3 

Problem 4

Frodo sometimes works as a pin-setter in a bowling alley. Write a program that instructs Frodo to transform the initial situation in the figure below into the final situation. (Be sure to finish the program with the stop command.) Frodo starts this task with ten pins in his pinbag. Name your program prog2.4. Test it with the command:

frodo -m map1.5 prog2.4

Can your program work in fewer moves?

Turn In

When you are done with your programs, put them in a subdirectory of your home directory, called lab2. Run the command below to check that all of your files are present: 

$ tree lab2
├── prog2.1
├── prog2.2
├── prog2.3
└── prog2.4

Extra files will be ignored. 


Each program is worth points which will be awarded if the execution of the program in the Middle Earth simulator is successful and according to specification
  • 5 points for each program (20 points total)
    • 2 for execution to completion
    • 3 for desired outcome