// MiGong01.java
public class MiGong01{
  //编写一个mian函数
  public static void main(String[]args){
    //先使用二维数组一个8行7列的的地图
    //用0表示可以走的路用1 表示路障
    int[][] map = new int[8][7];

    // 先把第一行和最后一行都设置为1
    for(int i = 0; i < 7; i++){

      map[0][i] = 1;
      map[7][i] = 1;

    }
    //把第一列和最后一列全部设置为1
    for(int j = 1; j < 7; j++){
      map[j][0] = 1;
      map[j][6] = 1;
    }

    //给4行2列 4行3列 3行3列设置路障
    map[3][1] = 1;
    map[3][2] = 1;
    map[2][2] = 1;

    //map原地图的输出
    System.out.println("===原始地图===");
    for(int i = 0; i < 8; i++){
      for(int j = 0; j < 7; j++){
        System.out.print(map[i][j] + " ");
      }
      System.out.println();
    }

    T t = new T();
    t.findWay(map,1,1);

    System.out.println("===出口地图===");
    for(int i = 0; i < 8; i++){
      for(int j = 0; j < 7; j++){
        System.out.print(map[i][j] + " ");
      }
      System.out.println();
    }

  }
}


class T{
  public boolean findWay(int[][] map,int n1, int n2){
    //思路分析
    //1.老鼠走过的路用2表示 走过了但是走不通用3表示
    //2.当int[][] = 2;时表示找到出口
    //3.方法策略 下- 右 -上 - 左
    if(map[6][5] == 2){
      return true;
    }else{
      if(map[n1][n2] == 0){
        map[n1][n2] = 2;
        if(findWay(map,n1 + 1 ,n2)){// down
          return true;
        }else if(findWay(map,n1 ,n2 +1)){//right
          return true;
        }else if(findWay(map,n1 - 1,n2)){//up
          return true;
        }else if(findWay(map,n1 ,n2 -1)){//left
          return true;
        }else{
          map[n1][n2] = 3;
          return false;
        }

      }else{
        return false;
      }
    }
  }
}