Example #1
0
  /**
   * Solves the maze for four robot starting positions
   *
   * @param draw
   */
  private boolean solve(boolean draw) {
    maze.draw();

    Point robotPositions[] = new Point[4];
    robotPositions[0] = new Point(1, 1); // bottom left
    robotPositions[1] = new Point(1, MAZE_SIZE); // top left
    robotPositions[2] = new Point(MAZE_SIZE, 1); // bottom right
    robotPositions[3] = new Point(MAZE_SIZE, MAZE_SIZE); // top right

    // one position for each robot
    boolean[] solved = {false, false, false, false};

    for (int i = 0; i < 4; i++) {
      if (robotPositions[i] != null) {
        solved[i] = maze.solve(robotPositions[i], maze.GetCentrePoint(), draw);
        // System.out.println("Robot " + (i + 1) + " path solved: " + solved[i]);
        if (draw) {
          StdDraw.clear();
          maze.draw();
        }
      }
    }

    return (solved[0] && solved[1] && solved[2] && solved[3]);
  }
 // a test client
 public static void main(String[] args) {
   // This line throws an index out bounds with any value in args ???
   // int N = Integer.parseInt(args[0]);
   // TODO: change this value to increase the complexity of the Maze
   int N = 10;
   Maze maze = new Maze(N);
   StdDraw.show(0);
   maze.draw();
   maze.solve();
 }
Example #3
0
  public Environment() {
    StdDraw.setCanvasSize(WINDOW_HEIGHT, WINDOW_LENGTH); // pixel size of window

    // Determines how the maze scales within the window
    StdDraw.setXscale(0, MAZE_SIZE + 2);
    StdDraw.setYscale(0, MAZE_SIZE + 2);

    validMaze = false;

    maze = new Maze(MAZE_SIZE); // create a new maze object

    StdDraw.show(0); // Show the maze window we have just created
    maze.draw(); // Draw the maze
    StdDraw.show(200); // Show this for 200 ms

    // pass the argument "true" to see the maze solve
    validMaze = solve(false); // solve the maze, but don't draw it
  }