mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-23 12:35:55 +08:00
@ -51,9 +51,7 @@ public class MazeRecursion {
|
||||
setWay2(map2, 1, 1);
|
||||
|
||||
// Print out the new map1, with the ball footprint
|
||||
System.out.println(
|
||||
"After the ball goes through the map1,show the current map1 condition"
|
||||
);
|
||||
System.out.println("After the ball goes through the map1,show the current map1 condition");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
System.out.print(map[i][j] + " ");
|
||||
@ -62,9 +60,7 @@ public class MazeRecursion {
|
||||
}
|
||||
|
||||
// Print out the new map2, with the ball footprint
|
||||
System.out.println(
|
||||
"After the ball goes through the map2,show the current map2 condition"
|
||||
);
|
||||
System.out.println("After the ball goes through the map2,show the current map2 condition");
|
||||
for (int i = 0; i < 8; i++) {
|
||||
for (int j = 0; j < 7; j++) {
|
||||
System.out.print(map2[i][j] + " ");
|
||||
@ -85,7 +81,7 @@ public class MazeRecursion {
|
||||
* means the ball has gone through the path but this path is dead end
|
||||
* 5. We will need strategy for the ball to pass through the maze for example:
|
||||
* Down -> Right -> Up -> Left, if the path doesn't work, then backtrack
|
||||
*
|
||||
*
|
||||
* @author OngLipWei
|
||||
* @version Jun 23, 2021 11:36:14 AM
|
||||
* @param map The maze
|
||||
@ -99,7 +95,8 @@ public class MazeRecursion {
|
||||
}
|
||||
if (map[i][j] == 0) { // if the ball haven't gone through this point
|
||||
// then the ball follows the move strategy : down -> right -> up -> left
|
||||
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2 first。
|
||||
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2
|
||||
// first。
|
||||
if (setWay(map, i + 1, j)) { // go down
|
||||
return true;
|
||||
} else if (setWay(map, i, j + 1)) { // go right
|
||||
@ -129,7 +126,8 @@ public class MazeRecursion {
|
||||
}
|
||||
if (map[i][j] == 0) { // if the ball haven't gone through this point
|
||||
// then the ball follows the move strategy : up->right->down->left
|
||||
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2 first。
|
||||
map[i][j] = 2; // we assume that this path is feasible first, set the current point to 2
|
||||
// first。
|
||||
if (setWay2(map, i - 1, j)) { // go up
|
||||
return true;
|
||||
} else if (setWay2(map, i, j + 1)) { // go right
|
||||
|
Reference in New Issue
Block a user