CMSC 201
Programming Project Three
a-MAZE-ing
Out: Monday 3/29/99
Original Due Date: Monday 4/12/99, before midnight
|
The Objective
The objective of this assignment is to get you familiar with using
arrays, separate compilation, and just a touch of using pointers as
parameters.
This project also contains a bit more problem solving and software
design than other projects so far.
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 dynamic maze.
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 we all draw the same mazes, use the
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 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
Other program requirements:
Sample Run
retriever[102] a.out
Please enter the random number generator seed: 4455
Starting at maze[10][10]
Trapped at maze[11][11]
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 . . . . . . . . .
10 . . . . . . . . . . ^ > v . . . . . . . .
11 . . . . . . . . . . > E v . . . . . . . .
12 . . . . . . . . . . ^ < < . . . . . . . .
13 . . . . . . . . . . . . . . . . . . . . .
14 . . . . . . . . . . . . . . . . . . . . .
15 . . . . . . . . . . . . . . . . . . . . .
16 . . . . . . . . . . . . . . . . . . . . .
17 . . . . . . . . . . . . . . . . . . . . .
18 . . . . . . . . . . . . . . . . . . . . .
19 . . . . . . . . . . . . . . . . . . . . .
20 . . . . . . . . . . . . . . . . . . . . .
In the maze above, the following moves were made
- Start at maze[10][10]
- Move UP to maze[9][10]
- Move RIGHT to maze[9][11]
- Move DOWN to maze[10][11]
- Move RIGHT tp maze[10][12]
- Move DOWN to maze[11][12]
- Move DOWN to maze[12][12]
- Move LEFT to maze[12][11]
- Move LEFT to maze[12][10]
- Move UP to maze[11][10]
- Move RIGHT to maze[11][11]
The mouse is trapped there with no un-visited squares to move to
retriever[102] a.out
Please enter the random number generator seed: 13
Starting at maze[10][10]
Out of Maze at maze[8][20]!!
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 . . . . . . . . . . . > v . . . . . . . >
9 . . . . . . . . . . > ^ v . . . . . . . ^
10 . . . . . . . . . . ^ . > v > v > > v > ^
11 . . . . . . . . . . . . . > ^ > ^ . > ^ .
12 . . . . . . . . . . . . . . . . . . . . .
13 . . . . . . . . . . . . . . . . . . . . .
14 . . . . . . . . . . . . . . . . . . . . .
15 . . . . . . . . . . . . . . . . . . . . .
16 . . . . . . . . . . . . . . . . . . . . .
17 . . . . . . . . . . . . . . . . . . . . .
18 . . . . . . . . . . . . . . . . . . . . .
19 . . . . . . . . . . . . . . . . . . . . .
20 . . . . . . . . . . . . . . . . . . . . .
retriever[103] a.out
Please enter the random number generator seed: 99999
Starting at maze[10][10]
Out of Maze at maze[17][0]!!
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 . . . . . . . . . . . . . . . . . . . . .
10 . . . . . . . . v < < . . . . . . . . . .
11 . . . . . . . . v . . . . . . . . . . . .
12 . . . . . . . . > v . . . . . . . . . . .
13 . . . . . . . . . v . > > v . . . . . . .
14 . . . . . . . . . > > ^ . v > > v . . . .
15 . . . . . . . . . . v < v < ^ v < . . . .
16 . . . . . . . . . . v ^ > > ^ > v . . . .
17 < < . . . . . . . v < ^ v < . . v . . . .
18 . ^ < < < < < < < < . ^ v ^ . . v . . . .
19 . . . . . . . . . . . ^ < ^ < < < . . . .
20 . . . . . . . . . . . . . . . . . . . . .
The results of using other selected random number seeds and starting
at maze[10][10]:
Seed | Result |
2 | Trapped at maze[16][7] |
3 | Out at maze[20][7] |
5 | Out at maze[14][0] |
1122 | Out at maze[0][4] |
8888 | Trapped at maze[14][10] |
12345 | Out at maze[0][6] |
13579 | Out at maze[20][3] |
24680 | Out at maze[0][10] |
Submitting the Program
To submit your project, type the following at the Unix prompt:
submit cs201 proj3 proj3.c maze.c maze.h
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 cs201 proj3