Maze Generator - Data Structures - Assignment 6 | CS 261, Assignments of Data Structures and Algorithms

Material Type: Assignment; Class: DATA STRUCTURES; Subject: Computer Science; University: Oregon State University; Term: Spring 2003;

Typology: Assignments

Pre 2010

Uploaded on 08/31/2009

koofers-user-uki
koofers-user-uki 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS 261 — Data Structures
Extra Credit: Maze Generator (20 pts)
Due date: Friday, May 9, 2003 (5:00 PM)
NOTE: this assignment is optional. All points for this assignment will be applied only to make up
homework point, not exam points. Thus, if you have not missed any points on your homework, you
would not benefit (at least in terms of a better grade) by doing this extra credit assignment.
Treat this paper as a specification for your assignment. Your code will be graded on correctness, read-
ability, and style. Study problems and exercises must be legible and will be graded on correctness.
What to do:
Programming:
1. Write a class called MazeGenerate that generates random mazes given a text file that has two inte-
gers on the first line to indicate the maze’s width and height (separated by white-space) and then it has
“height” rows with “width” characters on each row where each character is either a ‘*’ or a ‘-’ to indi-
cate that the cell is “valid” (that it is included in the maze) or “invalid” (not included in the maze),
respectively. The characters on each row should not be separated by white-space. As with the Maze
class, your MazeGenerate class should use two 2-D arrays: one to keep track of the walls of each
cell and one to indicate whether or not a cell has been visited. Use the same type of cell specification
as used in the Maze class for Homework #6 (i.e., a four bit code where each bit indicates that the cor-
responding wall of a cell is present). Initialize the “visited” array by marking as visited all the cells
that are invalid and marking as unvisited as all the cell that are valid. Initialize the “wall” array with a
0 for each invalid cell (so that no walls are drawn for this cell) and with a 15 for each valid cell (so
that each valid cell initially has all walls present).Generate the maze by starting with a random “valid”
cell and then iteratively choosing at random a valid direction to move (a direction that takes you to an
un-visited cell). Mark each cell visited and keep them in a stack so that when you reach a dead end
(where there are no adjacent cells that are unvisited) you can back up to a cell that allows you to con-
tinue. After generating the maze, randomly remove some walls (the actual number should be some
small percentage of total walls in the maze) between adjacent, “valid” cells to create loops in the
maze. Also, randomly choose two cells that represent dead-ends (i.e., cells that have three walls
present) and mark them as beginning and ending points. Output the final maze as a text file using the
same format used by the Maze class to read in a maze (20 pts).
What to turn in:
In class: a printout of your source file MazeGenerate.java.
Via the web: the file MazeGenerate.java.

Partial preview of the text

Download Maze Generator - Data Structures - Assignment 6 | CS 261 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CS 261 — Data Structures

Extra Credit: Maze Generator (20 pts)

Due date: Friday, May 9, 2003 (5:00 PM) NOTE: this assignment is optional. All points for this assignment will be applied only to make up homework point, not exam points. Thus, if you have not missed any points on your homework, you would not benefit (at least in terms of a better grade) by doing this extra credit assignment.

Treat this paper as a specification for your assignment. Your code will be graded on correctness, read- ability, and style. Study problems and exercises must be legible and will be graded on correctness.

What to do:

Programming:

  1. Write a class called MazeGenerate that generates random mazes given a text file that has two inte- gers on the first line to indicate the maze’s width and height (separated by white-space) and then it has “height” rows with “width” characters on each row where each character is either a ‘*’ or a ‘-’ to indi- cate that the cell is “valid” (that it is included in the maze) or “invalid” (not included in the maze), respectively. The characters on each row should not be separated by white-space. As with the Maze class, your MazeGenerate class should use two 2-D arrays: one to keep track of the walls of each cell and one to indicate whether or not a cell has been visited. Use the same type of cell specification as used in the Maze class for Homework #6 (i.e., a four bit code where each bit indicates that the cor- responding wall of a cell is present). Initialize the “visited” array by marking as visited all the cells that are invalid and marking as unvisited as all the cell that are valid. Initialize the “wall” array with a 0 for each invalid cell (so that no walls are drawn for this cell) and with a 15 for each valid cell (so that each valid cell initially has all walls present).Generate the maze by starting with a random “valid” cell and then iteratively choosing at random a valid direction to move (a direction that takes you to an un-visited cell). Mark each cell visited and keep them in a stack so that when you reach a dead end (where there are no adjacent cells that are unvisited) you can back up to a cell that allows you to con- tinue. After generating the maze, randomly remove some walls (the actual number should be some small percentage of total walls in the maze) between adjacent, “valid” cells to create loops in the maze. Also, randomly choose two cells that represent dead-ends (i.e., cells that have three walls present) and mark them as beginning and ending points. Output the final maze as a text file using the same format used by the Maze class to read in a maze ( 20 pts ).

What to turn in:

In class: a printout of your source file MazeGenerate.java.

Via the web: the file MazeGenerate.java.