Maze Generator
In the spring semester of 2024, during my sophomore year at the University of Rhode Island, I took a course on Data Structures and Algorithms. One of our assignments was to develop a maze generation application in C++ to reinforce our understanding of classes and dynamic arrays. At the time, I had very little knowledge of C++, so this assignment was my first real attempt at programming from scratch in this language.
The maze challenge was represented as a two-dimensional array, with each cell encoding the status of its four walls (north, south, east, west) using 4-bit integers.
To generate the maze, I implemented the following steps:
Initialization: I created an empty dynamic array and marked the starting cell as visited.
Maze Generation: I iteratively removed walls between adjacent cells to ensure a single path from the start to the end and that every cell was reachable from the start.
Randomization: I used a seed value to initialize the random number generator, ensuring different maze configurations with different seeds.
The program accepted command-line arguments for the seed value, number of rows, number of columns, and the output file name. The generated maze was saved in a text file, with each cell's walls encoded as integers separated by single whitespaces.
I designed and implemented a Maze
class, organizing the project into three files:
maze.h
: Class declaration.maze.cpp
: Implementation of class methods.main.cpp
: Driver program that processed command-line arguments and used the Maze class to generate the maze.
Here is an example of my program being run:
The top is the maze values generated with the seed value being 0, 15 wide, 15 long, and written to the example.txt file. When put into the maze visualizer you get this:
You can see each value is in binary, representing which walls should be open. This maze is correct because it only have one correct path to the end, starting at the top left and finishing at the bottom right.
This assignment not only solidified my understanding of classes and dynamic arrays in C++, but also enhanced my skills in algorithm implementation, command-line argument processing, and file I/O operations. Successfully completing this project demonstrated my ability to apply theoretical concepts to practical problems.