-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
53 lines (43 loc) · 1.28 KB
/
Copy pathMain.java
File metadata and controls
53 lines (43 loc) · 1.28 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
import model.*;
import engine.*;
import solver.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int[] rowReq = { 3, 2, 3, 1, 2 };
int[] colReq = { 2, 3, 2, 1, 2 };
Grid g = new Grid(5, 5, rowReq, colReq);
g.start = g.board[0][0];
g.goal = g.board[4][4];
g.board[1][3].blocked = true;
g.board[3][2].blocked = true;
Solver solver = new DPBacktrackingSolver();
while (true) {
g.printGrid();
System.out.println("MENU:");
System.out.println("1. Player place track (T)");
System.out.println("2. Run CPU (DP + Backtracking)");
System.out.println("3. Exit");
System.out.print("Choice: ");
int ch = sc.nextInt();
if (ch == 3)
break;
if (ch == 1) {
System.out.print("Enter row col: ");
int r = sc.nextInt();
int c = sc.nextInt();
if (!g.board[r][c].blocked && g.board[r][c] != g.start && g.board[r][c] != g.goal) {
g.board[r][c].track = true;
if (!ConstraintManager.isValid(g)) {
System.out.println("❌ Constraint violated!");
g.board[r][c].track = false;
}
}
} else if (ch == 2) {
boolean solved = solver.solve(g);
System.out.println("Solved: " + solved);
}
}
}
}