예제 #1
0
  // Loads all the nodes from files and initialises all maze-specific information.
  private void loadNodes(String fileName) {
    try {
      BufferedReader br =
          new BufferedReader(
              new InputStreamReader(
                  new FileInputStream(
                      pathMazes + System.getProperty("file.separator") + fileName + ".txt")));
      String input = br.readLine();

      // preamble
      String[] pr = input.split("\t");

      this.name = pr[0];
      this.initialPacManNodeIndex = Integer.parseInt(pr[1]);
      this.lairNodeIndex = Integer.parseInt(pr[2]);
      this.initialGhostNodeIndex = Integer.parseInt(pr[3]);
      this.graph = new Node[Integer.parseInt(pr[4])];
      this.pillIndices = new int[Integer.parseInt(pr[5])];
      this.powerPillIndices = new int[Integer.parseInt(pr[6])];
      this.junctionIndices = new int[Integer.parseInt(pr[7])];

      int nodeIndex = 0;
      int pillIndex = 0;
      int powerPillIndex = 0;
      int junctionIndex = 0;

      input = br.readLine();

      while (input != null) {
        String[] nd = input.split("\t");

        Node node =
            new Node(
                Integer.parseInt(nd[0]),
                Integer.parseInt(nd[1]),
                Integer.parseInt(nd[2]),
                Integer.parseInt(nd[7]),
                Integer.parseInt(nd[8]),
                new int[] {
                  Integer.parseInt(nd[3]),
                  Integer.parseInt(nd[4]),
                  Integer.parseInt(nd[5]),
                  Integer.parseInt(nd[6])
                });

        graph[nodeIndex++] = node;

        if (node.pillIndex >= 0) pillIndices[pillIndex++] = node.nodeIndex;
        else if (node.powerPillIndex >= 0) powerPillIndices[powerPillIndex++] = node.nodeIndex;

        if (node.numNeighbouringNodes > 2) junctionIndices[junctionIndex++] = node.nodeIndex;

        input = br.readLine();
      }
      br.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }
예제 #2
0
  /*
   * Loads the shortest path distances which have been pre-computed. The data contains the shortest distance from
   * any node in the maze to any other node. Since the graph is symmetric, the symmetries have been removed to preserve
   * memory and all distances are stored in a 1D array; they are looked-up using getDistance(-).
   */
  private void loadDistances(String fileName) {
    this.shortestPathDistances = new int[((graph.length * (graph.length - 1)) / 2) + graph.length];

    try {
      BufferedReader br =
          new BufferedReader(
              new InputStreamReader(
                  new FileInputStream(
                      pathDistances + System.getProperty("file.separator") + fileName)));
      String input = br.readLine();

      int index = 0;

      while (input != null) {
        shortestPathDistances[index++] = Integer.parseInt(input);
        input = br.readLine();
      }
      br.close();
    } catch (IOException ioe) {
      ioe.printStackTrace();
    }
  }