Exemplo n.º 1
0
  public static void main(String[] args) throws FileNotFoundException {
    Maze f;
    f = new Maze("data3.dat", true); // true animates the maze.

    f.clearTerminal();
    f.solve();

    f.clearTerminal();
    System.out.println(f);
  }
Exemplo n.º 2
0
  public static void main(String[] args) {

    Maze m = new Maze("data.dat", true);
    m.solve();

    if (m.debug) {
      System.out.println(m.maze.length + "/" + m.maze[0].length);
      System.out.println(m.maze[1][1]);
      System.out.println(m.startx);
    }
  }
Exemplo n.º 3
0
 public static void main(String args[]) {
   Maze m = new Maze();
   m.main();
 }
Exemplo n.º 4
0
  // Recursivly goes through the maze until it finds the finish line
  public boolean findTheWay(Point p) {
    boolean northBarrier = false;
    boolean southBarrier = false;
    boolean eastBarrier = false;
    boolean westBarrier = false;
    int data = myMaze.getMazeData(p.y, p.x);
    // Returns false if Y position is out of range
    if (p.y < 0 || p.y > height) return false;

    // Returns false if X position is out of range
    if (p.x < 0 || p.x > height) return false;
    // Finds which paths are blocked for point P
    if (data > 14) {
      northBarrier = true;
      southBarrier = true;
      eastBarrier = true;
      westBarrier = true;
    }
    if (data <= 14 && data - 8 >= 0) {
      eastBarrier = true;
      data -= 8;
    }
    if (data <= 7 && data - 4 >= 0) {
      southBarrier = true;
      data -= 4;
    }
    if (data <= 3 && data - 2 >= 0) {
      westBarrier = true;
    }
    if (data % 2 != 0) {
      northBarrier = true;
    }

    // Returns true if the goal is reached
    if (p.equals(goal)) return true;

    // Adds the point to the path of points
    path.add(p);
    placesGone.add(p);

    // Checks for North
    if (!northBarrier && !placesGone.contains(new Point(p.x, p.y - 1))) {
      if (p.y - 1 >= 0) {
        if (findTheWay(new Point(p.x, p.y - 1))) {
          return true;
        }
      }
    }
    // Checks for South
    if (!southBarrier && !placesGone.contains(new Point(p.x, p.y + 1))) {
      if (p.y + 1 < height) {
        if (findTheWay(new Point(p.x, p.y + 1))) {
          return true;
        }
      }
    }

    // Checks for East
    if (!eastBarrier && !placesGone.contains(new Point(p.x + 1, p.y))) {
      if (p.x + 1 < width) {
        if (findTheWay(new Point(p.x + 1, p.y))) {
          return true;
        }
      }
    }

    // Checks for West
    if (!westBarrier && !placesGone.contains(new Point(p.x - 1, p.y))) {
      if (p.x - 1 >= 0) {
        if (findTheWay(new Point(p.x - 1, p.y))) {
          return true;
        }
      }
    }
    // Removes the point if its not part of the final solution
    path.remove(path.size() - 1);
    return false;
  }
Exemplo n.º 5
0
 // Creates a new maze and adds a maze listner to the maze
 public SolveMaze() {
   myMaze = new Maze(height, width);
   MazeListen mListener = new MazeListen();
   myMaze.addMazeListener(mListener);
 }