forked from fineanmol/Hacktoberfest2025
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMazeWithObstacles.java
More file actions
27 lines (25 loc) · 857 Bytes
/
MazeWithObstacles.java
File metadata and controls
27 lines (25 loc) · 857 Bytes
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
public class MazeWithObstacles {
public static void main(String[] args) {
boolean[][] board = {
{true, true, true},
{true, false, true},
{true, true, true}
};
pathRestriction("", board, 0, 0);
}
static void pathRestriction(String p, boolean[][] maze, int r, int c){ //boolean array
if (r == maze.length - 1 && c == maze[0].length - 1){ //0 = length of col
System.out.println(p);
return;
}
if (!maze[r][c]){ // if maze[r][c] == false // if not true //if there is a obstacle
return;
}
if (r < maze.length - 1){
pathRestriction(p + 'D', maze, r+1, c); //down
}
if (c < maze[0].length - 1){
pathRestriction(p + 'R', maze, r, c+1); //right
}
}
}