示例#1
0
  public static void filehandler() {
    try {
      int i = 0;
      File file = new File("map1.txt"); // SPECIFY THE FILE NAME HERE
      FileInputStream fis = new FileInputStream(file);
      BufferedInputStream bis = new BufferedInputStream(fis);
      BufferedReader d = new BufferedReader(new InputStreamReader(bis));
      String line = d.readLine();
      line = line.trim();
      String temp[] = line.split(" ");
      row = Integer.parseInt(temp[0]);
      BFS.setMax_Row(row - 1); // SETTING THE MAX_ROW AS ROW-1
      col = Integer.parseInt(temp[1]);
      BFS.setMax_Col(col - 1); // SETTING THE MAX_COL AS COL-1
      line = d.readLine();
      line = line.trim();
      temp = line.split(" ");
      int startx = Integer.parseInt(temp[0]);
      BFS.setStartx(startx); // SETTING THE START POSITION OF THE SEARCH ON X AXIS
      int starty = Integer.parseInt(temp[1]);
      BFS.setStarty(starty); // SETTING THE START Y POSITION OF THE SEARCH
      int j = i = 0;
      while (i < row) // STORING THE GRAPH FROM THE FILE INTO A VARIABLE
      {
        line = d.readLine();
        char ch[] = line.toCharArray();
        for (int k = 0; k < col; k++) {
          Graph[i][k] = ch[k];
          if (ch[k] != '.') {
            Message_Obtained.add(j);
            j++;
          }
        }
        i++;
      }
      BFS.setGraph(Graph);
      BFS.setGoals(Message_Obtained);
      getpos();
      i = 0;
      while (i < row) // Reading the cost map from the file and saving it
      {
        line = d.readLine();
        line = line.trim();
        temp = line.split(" +");
        for (j = 0; j < col; j++) {
          cost_map[i][j] = Double.parseDouble(temp[j]);
        }
        i++;
      }
      BFS.setMap_cost(cost_map);
    } catch (IOException e) {

    }
  }