뭐가 문젤가요ㅠㅠ
public class MazePath {
private int m;
private int n;
private int dir;
private int[][] maze;
private int[][] mark;
private int[][] move;
private ArrayStack stack1, stack2;
private int i, j;
private int next_i, next_j;
public MazePath() {
m = 7;
n = 6;
dir = 0;
mark = new int[m + 2][n + 2];
for (int num1 = 0; num1 < m + 2; num1++) {
for (int num2 = 0; num2 < n + 2; num2++)
mark[num1][num2] = 0;
}
maze = new int[m + 2][n + 2];
for (int num1 = 0; num1 < m + 2; num1++) {
for (int num2 = 0; num2 < n + 2; num2++)
maze[num1][num2] = 1;
}
maze[1][1] = 0;
maze[1][4] = 0;
maze[2][1] = 0;
maze[2][2] = 0;
maze[2][4] = 0;
maze[3][2] = 0;
maze[3][3] = 0;
maze[3][4] = 0;
maze[4][3] = 0;
maze[4][4] = 0;
maze[4][5] = 0;
maze[5][1] = 0;
maze[5][2] = 0;
maze[5][3] = 0;
maze[6][2] = 0;
maze[6][4] = 0;
maze[6][5] = 0;
maze[6][6] = 0;
maze[7][1] = 0;
maze[7][2] = 0;
maze[7][3] = 0;
maze[7][4] = 0;
maze[7][6] = 0;
move = new int[4][2];
move[0][0] = -1;
move[1][0] = 0;
move[2][0] = 1;
move[3][0] = 0;
move[0][1] = 0;
move[1][1] = 1;
move[2][1] = 0;
move[3][1] = -1;
stack1 = new ArrayStack();
stack2 = new ArrayStack();
}
public void show() {
i = 1;
j = 1;
dir = 1;
stack1.push(1);
stack2.push(1);
mark[1][1] = 1;
while ((!stack1.isEmpty()) && (!stack2.isEmpty())) {
i = (int) stack1.pop();
j = (int) stack2.pop();// 이전 칸으로 이동
while (dir <= 3) {// 시도해 볼 방향이 있는 한 ㄱㅔ속 시도
next_i = i + move[dir][0];// 다음 시도 할 행을 설정
next_j = j + move[dir][1];// 다음 시도할 열을 설정
if (next_i == m && next_j == n) {// 미로경로 발견
System.out.print("There path is as follow.");
while ((!stack1.isEmpty()) && (!stack2.isEmpty())) {
System.out.print("<" + stack1.pop() + ","
+ stack2.pop() + ">");// 스택에 저장된 경로 출력
}
return ;
}
if (maze[next_i][next_j] == 0 && mark[next_i][next_j] == 0) {
mark[next_i][next_j] = 1;
stack1.push(i);
stack2.push(j);
i = next_i;
j = next_j;
dir = 0;
} else
dir++;
}
}
System.out.print("There is no path.");
}
public static void main(String[] args) {
MazePath mazePath = new MazePath();
mazePath.show();
}
}