-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
41 lines (31 loc) · 1.31 KB
/
Main.java
File metadata and controls
41 lines (31 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner inputScanner = new Scanner(System.in);
// ask for maze size
System.out.print("Please enter the maze dimensions: ");
String sizeLine = inputScanner.nextLine();
String[] dimensions = sizeLine.split(",");
int rows = Integer.parseInt(dimensions[0].trim());
int cols = Integer.parseInt(dimensions[1].trim());
System.out.println("\nGenerated Maze:");
// build a maze with the requested size
Maze maze = new Maze(rows, cols);
maze.generateMaze();
// print the maze to the console
Visualization.displayMaze(maze);
System.out.println("\nMaze Solver:");
// run depth first search to find a path
MazeSolver solver = new MazeSolver(maze);
List<Cell> pathCells = solver.solveDFS();
// show the path if we found one
if (pathCells.isEmpty()) {
System.out.println("No path found!");
} else {
Visualization.displaySolution(maze, pathCells);
System.out.println("\nPath length: " + pathCells.size() + " cells");
}
inputScanner.close();
}
}