CS 1713 Section 3, Spring 1997
Assignment 4: Loops and Files: Mars Mission

For this assignment, you will write a program that checks a plan for maneuvering a vehicle around an obstacle to a target, given a limited amount of fuel.

The Mars Land Rover Mission

An unmanned rocket has been launched to the planet Mars to study the red planet. The plan was that the rocket would release a lander, which would land on the Martian surface. From the lander, an automated land rover would be released and would drive around, gathering and analyzing rock samples nearby, and sending its results back to the Earth via the orbiting rocket. The the chosen landing site is an area 100 kilometers due east of Olympus Mons, an enormous volcano. This area was specifically targeted by scientists because of interesting geological phenomenae.

The Problem

Unfortunately, but typically, the engineers on the project were holding their map upside down and thus accidentally caused the lander to land 100 km due west of Olympus Mons. The rover must analyze rocks from within 5 km of the intended landing site or the mission will be a failure and the engineers will be sent to the hell currently occupied by the Hubble space telescope engineers. The engineers have decided to send commands to the land rover to drive it over to the target site. They will have to steer the rover around the volcano since it is surrounded by a steep circular escarpment (cliff) 450 km in diameter. The engineers move the rover by sending it commands to turn by a certain number of degrees or move forward a certain number of kilometers. The rover has a tank filled with 15 liters of fuel, and can go 70 km per liter over the rough Martian terrain (turning consumes no fuel). They would like to move the rover to the site and have some fuel left over for a little exploration. Here is an ASCII drawing of the situation, in a coordinate system where the y axis points north, the x axis points east, and the origin is the lander.
                        ######## 
                     ###############
                   ################## 
                  #####################
                 #######################
                 ##### Olympus Mons #### 
(0,0)           #########################              (750,0)
 *|<--100 km-->|##<-------450 km------>##|<--200 km-->|X
Lander          #########################            Target
                 ####################### 
                 #######################
                  #####################
                   ################## 
                     ###############
                        ######## 

The rover is guided by a plan, or set of commands and parameters. The turn command is given by the character r (for rotate) and the move forward command is given by the character f. For example, consider the following plan:

f 99
r 90
f 225
r -90
f 552
r -90
f 225
r 90
f 100
This says to move forward (initially east) 99 km, stopping 1 km from the volcano, turn right 90 degrees, move forward (now south) 225 km, turn left 90 degrees (i.e., rotate -90 degrees), move forward 552 km, passing to the south of the volcano, turn left 90 degrees, move forward 225 km, turn right 90 degrees then move forward 100 km. The rover would now be at coordinate (751, 0), within 5 km of the target, which is at (750, 0). However, this isn't such a good plan, since the rover has to go a total of 99+225+552+275+100 = 1201 km, exhausting its fuel supply (1201km / 70km/L is about 17 liters) before reaching the target.

The engineers have proposed several plans for maneuvering the rover to the site. They don't know which plan is the best. They need to check the plans to see which ones will work and which one has the most fuel left over at the end. They need a simulator for the rover that will tell them whether a given plan will bump into the volcano, run out of fuel, miss the target by more than 5 km, etc.

The Assignment

Your job is to write a program called rover.c that simulates the rover as it follows a plan given in a file. The filename should be a command line argument, so if the name of a plan were plan, you would invoke your program with "rover plan". Your program should: For example, on the plan presented above, your program should produce output similar to this:
command: forward  99.00
position: ( 99.00,   0.00) orientation:   0.00 fuel:  13.59
command: rotate  90.00
position: ( 99.00,   0.00) orientation:  90.00 fuel:  13.59
command: forward 225.00
position: ( 99.00, 225.00) orientation:  90.00 fuel:  10.37
command: rotate -90.00
position: ( 99.00, 225.00) orientation:   0.00 fuel:  10.37
command: forward 552.00
position: (651.00, 225.00) orientation:   0.00 fuel:   2.49
command: rotate -90.00
position: (651.00, 225.00) orientation: -90.00 fuel:   2.49
command: forward 225.00
position: (651.00,   0.00) orientation: -90.00 fuel:  -0.73
command: rotate  90.00
position: (651.00,   0.00) orientation:   0.00 fuel:  -0.73
command: forward 100.00
position: (751.00,   0.00) orientation:   0.00 fuel:  -2.16
out of fuel!
within 5 kilometers; ok to take sample.
On runner, in the directory ~djimenez/cs1713, there are four plan files, plan1 through plan4; run your program on these files and make sure it works. Make sure your source code is throroughly commented. To turn in the program, e-mail your source code to djimenez@ringer.cs.utsa.edu with subject "CS1713 Assignment 4".

Contest for Extra Credit

For extra credit, design and test your own plan for getting the rover to within 5 km of the target. The student with the best plan will be awarded 5 extra points on this program; the second and third best will be awarded 3 extra points. "Best" means with the most fuel left over upon reaching the target according to the instructor's version of the program; in the event of a tie, the plan that arrives closer to the target wins. If it is still a tie, the first student to turn in the tied plan wins. Turn in your plan in a separate e-mail to djimenez@ringer.cs.utsa.edu with subject "Plan contest".

Programming Issues

This assignment is due Monday, February 17, 1997 at midnight.