Please read the remarks about programming problems for this course.
Maze construction is an application of the disjoint-set data structure. In this assignment you will develop the disjoint-set abstract data type (ADT), and then use your disjoint-set ADT to assist in building a graphical maze. This assignment has three parts:
If you are using a Mac, the command line to build your graphical program is
Visual Studio users need do nothing special if all the files are in the appropriate locations.
DisjointSet
. Your
DisjointSet
class must support the following
operations:
Find
method that returns the
equivalence class (representative element)
of an element,
Union
method that accepts
two set elements and merges their
equivalence classes,
Split
method that partitions the
set into blocks of size one (all elements in their
own equivalence class, unrelated to any other
elements in the set), and
Cardinality
method that returns the
number of equivalence classes in the set.
Use the algorithm we considered in class. First begin with a proto-puzzle in which no room is connected to any other room. This corresponds to a disjoint-set in which the size of all the equivalence classes is one. (If drawn at this point, the unsolvable maze would look like the output of drawgrid.cpp.) Then enter a loop that continues until only one equivalence class remains, the one that contains all the elements in the set. Each time through the loop your algorithm should select a room at random and also select a neighboring room (north, south, east, or west) at random. If these two rooms are not part of the same equivalence class, union them; otherwise, do not union them. Eventually all the rooms will be in the same equivalence class which means there will exist exactly one path from the entrance to the exit.
Even though the grid is two dimensional, you probably will find it easier to represent it as a linear sequence. Be sure to take note in class for more information about how to map a room to an index within the sequence (and vice-versa) and how to compute the indices of its neighbors.
When you are satisfied that your code is complete and correct, consolidate all your code into one source file named with your last name; for example, halterman.cpp. It should be possible to compile this single source file to produce the executable. Submit this source file to eclass.