Assigned | Monday, Sept 12, 2011 |
Program Due | 11:59pm Tuesday Sep 20, 2011 |
Points | 40 |
Updates |
The Objective
The objective of this assignment is to become familiar with the C programming language as well as compiling and executing C programs.The Background
Not all programs are written as part of multi-million dollar projects, nor are they "killer apps". Sometimes we just write programs that are entertaining. This project is one of those programs -- just for fun.The Task
You are to write a program that simulates a mouse stuck in a maze, trying to escape. The maze is conceptually a 21 - by - 21 checker board made up of 441 squares. A mouse starts in the middle square of the maze and attempts to escape the maze by moving off any edge. The rules of mouse movement are given below.- The mouse starts in the middle square -- maze[10][10].
- The mouse chooses a random direction (all equally likely) to determine the
square to move to next.
So that eveyone's mouse follows the same path, use following values:- 1 = left
- 2 = right
- 3 = up
- 4 = down
- The mouse may not move to a square that it has visited before. If the random direction you have chosen is not permitted, choose another random direction.
- If the mouse has no legal moves (because it has previously visited all the surrounding squares) -- You LOSE
- If the mouse moves out of the maze in any direction -- YOU WIN
Program Requirements
- Your program should prompt the user for a positve integer to seed
the random number generator.
- Win or Lose, your program should display the maze (including row and
column numbers) and indicate the
path the mouse travelled. Use the following symbols to indicate the direction
the mouse moved from each square.
- Print "<" to indicate that the mouse moved left
- Print ">" to indicate that the mouse moved right
- Print "v" to indicate that the mouse moved down
- Print "^" to indicate that the mouse moved up
- Print "." (period) for squares that the mouse never visited
- Print "E" to indicate the square on which the mouse ended if trapped
For example, if the mouse was at maze[6][5] and chose to move left from there to maze[6][4], then the display would show "<" at maze[6][5].
- Indicate the co-ordinates of the starting square and where the mouse got trapped or escaped the maze.
- Although functions are not required for this project (since we haven't covered them in class yet), feel free to use functions if you are comfortable doing so.
Notes
- Your program file must be named project1.c otherwise our grading scripts won't work properly and points will be deducted from your project score.
- You may assume the user will input a valid non-negative integer when prompted to do so.
- To randomly choose the direction in which the mouse will move, use the C library's random number generator function rand( ). This function will return a new random integer between 0 and RAND_MAX (a very large int) each time it is called. To initialize the random number generator with the value input from the user, call the function srand( ). Be sure to call srand( ) only once. Refer to your K & R book or see the Unix man pages for more information on rand( ) and srand( ).
- Since the srand( ) function parameter is an unsigned integer, use the %u specifier when reading the seed input by the user.
Sample Run
Project Grading
This project is worth 40 points broken down as follows- We will choose RNG seeds that result in your program terminating in
each of the 5 possible ways as listed below (6 points each).
- Escaping at the top
- Escaping at the bottom
- Escaping from the right
- Escaping from the left
- Being trapped
- 10 points for coding style and conventions
Submitting the Program
To submit your project, type the following at the Unix prompt:submit cs313 Proj1 project1.c
To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show all files that you submitted in a format similar to the Unix 'ls' command.
submitls cs313 Proj1