문제
미로탐색문제를 해결하는 문제입니다 이를 해결하는 프로그램의 다음 실행상태에 대해 빈칸을 채우세요
프로그램의 실행순서 및 실행상태
1 public static void main( String[] args ) {
캐릭터 현재 위치의 줄번호를 입력하세요 : 3
캐릭터 현재 위치의 칸번호를 입력하세요 : 5
2 if ( move( row, column )
Fb private static int move( int row, int column ) {
F3 map[row][column] = VISITED;
■■■■■■■
■ ■ ■
■ ■ ■■■
■■■ ■옷■
■ 문
■■■■■■■
F4 if ( move( row + 1, column )
Fb private static int move( int row, int column ) {
F3 map[row][column] = VISITED;
■■■■■■■
■ ■ ■
■ ■ ■■■
■■■ ■ ■
■ 옷문
■■■■■■■
F4 if ( move( row + 1, column )
Fb private static int move( int row, int column ) {
F16 return 0;
Fe }
F5 == SUCCESS )
F7 if ( move( row, column + 1 )
Fb private static int move( int row, int column ) {
■■■■■■■
■ ■ ■
■ ■ ■■■
■■■ ■ ■
■ 옷
■■■■■■■
F2 return SUCCESS;
Fe }
F8 == SUCCESS )
F9 return SUCCESS;
Fe }
F5 == SUCCESS )
F6 return SUCCESS;
Fe }
3 == SUCCESS )
4 System.out.println( "\n미로 맵 탈출 성공!" );
미로 맵 탈출 성공!
7 }
프로그램 코드
import java.util.Scanner;
public class MazeMove
{
private static int[][] map = {
{ 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 1, 0, 1 },
{ 1, 0, 1, 0, 1, 1, 1 },
{ 1, 1, 1, 0, 1, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 2 },
{ 1, 1, 1, 1, 1, 1, 1 }
};
private static final int HEIGHT = 6, WIDTH = 7;
private static int previousRow = -1, previousColumn = -1;
private static void printMap( int row, int column ) {
if ( ( row == previousRow ) && ( column == previousColumn ) )
return;
String[] symbol = { " ", " \033[44m \033[0m", " \033[34m문 \033[0m", " " };
for( int i = 0; i < HEIGHT; i++ ) {
for( int j = 0; j < WIDTH; j++ ) {
if( ( i == row ) && ( j == column ) )
System.out.print( "옷" );
else
System.out.print( symbol[ map[i][j] ] );
}
System.out.println();
}
System.out.println();
previousRow = row;
previousColumn = column;
}
private static final int SUCCESS = 2;
private static final int VISITED = 3;
private static final int NOTVISITED = 0;
Fb private static int move( int row, int column ) {
if ( ( row < 0 ) || ( HEIGHT <= row ) || ( column < 0 ) || ( WIDTH <= column ) )
F1 return 0;
else if ( map[row][column] == SUCCESS ) {
printMap( row, column );
F2 return SUCCESS;
}
else if ( map[row][column] == NOTVISITED ) {
F3 map[row][column] = VISITED;
printMap( row, column );
F4 if ( move( row + 1, column )
F5 == SUCCESS )
F6 return SUCCESS;
printMap( row, column );
F7 if ( move( row, column + 1 )
F8 == SUCCESS )
F9 return SUCCESS;
printMap( row, column );
F10 if ( move( row - 1, column )
F11 == SUCCESS )
F12 return SUCCESS;
printMap( row, column );
F13 if ( move( row, column - 1 )
F14 == SUCCESS )
F15 return SUCCESS;
printMap( row, column );
}
F16 return 0;
Fe }
1 public static void main( String[] args ) {
Scanner scan = new Scanner( System.in );
System.out.print( "캐릭터 현재 위치의 줄번호를 입력하세요 : " );
int row = scan.nextInt();
System.out.print( "캐릭터 현재 위치의 칸번호를 입력하세요 : " );
int column = scan.nextInt();
2 if ( move( row, column )
3 == SUCCESS )
4 System.out.println( "\n미로 맵 탈출 성공!" );
5 else
6 System.out.println( "\n미로 맵 탈출 실패" );
scan.close();
7 }
}