-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
67 lines (49 loc) · 2.05 KB
/
Main.java
File metadata and controls
67 lines (49 loc) · 2.05 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* Krish Patel
UTD Net ID: KKP230002
CS 2336.009
Project: Maze Generator and Solver
File for user interaction for inputting dimensions
and calling classes to generate and solve the maze
Main.java
*/
import java.util.*;
public class Main {
public static void main(String[] args) {
// Initialze scanner for user input
Scanner scannerInput = new Scanner(System.in);
// Prompt user for maze dimensions
System.out.print("Enter maze dimensions: ");
String inputDimensions = scannerInput.nextLine();
// Handle input formats
inputDimensions = inputDimensions.replace(",", " "); // Replaves any commas with spaces
// Create new scanner to determine dimensions one by one
Scanner num1by1 = new Scanner(inputDimensions);
// Output error message for invalid input (Not numbers)
if (!num1by1.hasNextInt()) {
System.out.println("Invalid input. Please enter two integers for dimensions.");
scannerInput.close();
num1by1.close();
return;
}
// Read rows and columns
int rows = num1by1.nextInt();
int cols = num1by1.nextInt();
// Instantiate all classes
Maze maze = new Maze(rows, cols);
MazeSolver mazeSolver = new MazeSolver(maze);
Visualization viewer = new Visualization(maze);
// Calls for random generation of maze
maze.generateMazeRandomly(System.currentTimeMillis());
// Intialize start and end cells
Cell startCell = new Cell(0, 0);
Cell endCell = new Cell(rows - 1, cols - 1);
// Generated maze output without path
System.out.println("\nGenerated Maze (S=start, E=end):");
viewer.printMazeWithPath(null, startCell, endCell);
// Solved maze output with path
List<Cell> correctPath = mazeSolver.solveDFS(startCell, endCell);
System.out.println("\nSolved Maze with Path: \n");
viewer.printMazeWithPath(correctPath, startCell, endCell);
scannerInput.close();
}
}