This project is a Java written assignment that generates a random maze using Prim's Algorithm and finds a path from the start to the end using Depth-First Search. The maze and the solution path are visualized using ASCII characters.
The project is composed of five Java files:
Cell.java: Defines a single node/cell in the maze, storing its row and column coordinates.Maze.java: Manages the maze structure. Contains the logic for Prim's Algorithm to generate the maze walls and manages the connectivity.MazeSolver.java: Implements the Depth-First Search algorithm to find a path between the start and goal cells.Visualization.java: Contains methods to print the maze structure and the solution path using ASCII graphics.Main.java: Handles user input for maze dimensions, instantiates the classes, and facilitates maze generation, solving, and viewing process.
I chose Prim's algorithm because it makes mazes that look and feel balanced (Also required in project details)
The maze is stored as a simple list-of-lists graph using integer locations (r*cols+c). That keeps the solver straightforward and uses little memory.
Walls are tracked with two boolean grids which makes printing the maze in ASCII easy.
Cell is just a small immutable pair (row, col) so comparing cells and using them in sets/maps is simple.
I used an iterative DFS with a parent array for the solver because it's easy to implement, avoids recursion limits, and makes reconstructing the path trivial. (Also required by the project details)
Visualization is kept in its own class so the maze logic stays clean. The generator accepts a seed so you can reproduce specific mazes when you want.
This project is a standard Java command-line application and requires a Java Development Kit (JDK) installed on your system.
Open your terminal or command prompt in the directory containing all the .java files and compile them:
javac Cell.java Maze.java MazeSolver.java Visualization.java Main.java
java MainUsage example: when prompted enter two integers for rows and columns, e.g. 10 15 or 10,15.