Mouse Maze Project

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.
  1. The mouse starts in the middle square -- maze[10][10].
  2. 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. 1 = left
    2. 2 = right
    3. 3 = up
    4. 4 = down
  3. 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.
  4. If the mouse has no legal moves (because it has previously visited all the surrounding squares) -- You LOSE
  5. If the mouse moves out of the maze in any direction -- YOU WIN

Program Requirements

  1. Your program should prompt the user for a positve integer to seed the random number generator.
  2. 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.
    1. Print "<" to indicate that the mouse moved left
    2. Print ">" to indicate that the mouse moved right
    3. Print "v" to indicate that the mouse moved down
    4. Print "^" to indicate that the mouse moved up
    5. Print "." (period) for squares that the mouse never visited
    6. 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].

  3. Indicate the co-ordinates of the starting square and where the mouse got trapped or escaped the maze.
  4. 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

  1. 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.
  2. You may assume the user will input a valid non-negative integer when prompted to do so.
  3. 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( ).
  4. Since the srand( ) function parameter is an unsigned integer, use the %u specifier when reading the seed input by the user.

Sample Run

linux1[107]% a.out Input RNG seed: 9 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0 . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . 2 . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . . . . . . . . . . . . 4 . . . . . . . . . . . . . . . . . . . . . 5 . . . . . . . . . . . . . . . . . . . . . 6 . . . . . . . . . . . . . . . . . . . . . 7 . . . . . . . . . . . . . . . . . . . . . 8 . . . . . . . . . . . . . . . . . . . . . 9 . . . . . . . . . . . > > v > v . . . . . 10 . . . . . . . . . . v ^ < > ^ > v . . . . 11 . . . . . . . . . . > v ^ . . v < . . . . 12 . . . . . . . . . . . > ^ . . > > v . . . 13 . . . . . . . . . . . . . . . . . > v . . 14 . . . . . . . . . . . . . . . . . . v . . 15 . . . . . . . . . . . . . . . . v < < . . 16 . . . . . . . . . . . . . . . . > v > v . 17 . . . . . . . . . . . . . . . . . > ^ > v 18 . . . . . . . . . . . . . . . . . . . . v 19 . . . . . . . . . . . . . . . . . . . . v 20 . . . . . . . . . . . . . . . . . . . . v The mouse started at: ( 10, 10 ) The mouse escaped the maze at: ( 20, 20 ) linux1[108]% a.out Input RNG seed: 12345 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 0 . . . . . . . . . . . . . . . . . . . . . 1 . . . . . . . . . . . . . . . . . . . . . 2 . . . . . . . . . . . . . . . . . . . . . 3 . . . . . . . . . . > > v . . . . . . . . 4 . . . . . . . . . . ^ v < . . . . . . . . 5 . . . . . . . . . . ^ > > v . . . . . . . 6 . . . . . . . . . . ^ E < < . . . . . . . 7 . . . . . . . . . . ^ < < < < . . . . . . 8 . . . . . . . . . . . > > > ^ . . . . . . 9 . . . . . . . . . . . ^ v < < . . . . . . 10 . . . . . . . . . . v ^ < > ^ . . . . . . 11 . . . . . . . . . . > > v ^ < . . . . . . 12 . . . . . . . . . . . . > > ^ . . . . . . 13 . . . . . . . . . . . . . . . . . . . . . 14 . . . . . . . . . . . . . . . . . . . . . 15 . . . . . . . . . . . . . . . . . . . . . 16 . . . . . . . . . . . . . . . . . . . . . 17 . . . . . . . . . . . . . . . . . . . . . 18 . . . . . . . . . . . . . . . . . . . . . 19 . . . . . . . . . . . . . . . . . . . . . 20 . . . . . . . . . . . . . . . . . . . . . The mouse started at: ( 10, 10 ) The mouse was trapped at: ( 6, 11 )

Project Grading

This project is worth 40 points broken down as follows

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