Exemplo n.º 1
0
  public static void main(String[] args) {
    int count = 0;

    int equal = 0;

    for (int i = 0; i < 100; ++i) {
      Maze maze = new Maze(10, 10);
      // maze.initTestCase();

      maze.printMaze();
      System.out.println(maze.startPoint);
      System.out.println(maze.targetPoint);
      maze.adaptiveAstar();
      int a = maze.numOfExpandNodes;
      System.out.println("");
      maze.repeatedFAstar();
      int b = maze.numOfExpandNodes;
      System.out.println("");
      maze.repeatedBAstar();

      if (maze.success) {
        if (b > a) count++;
        else if (b == a) equal++;
        else {
          System.out.println("*");
        }
      }
    }

    System.out.println(count);
    System.out.println(equal);
  }
Exemplo n.º 2
0
 public int testTiebreak(PrintWriter writer) {
   int expanded = search.run(cells, false, true, false);
   maze.printMaze("PreferSmallG.txt");
   if (expanded == 0) {
     writer.println("Repeated A* by preferring smaller g value cannot reach the target.");
     writer.println();
   } else {
     writer.println("Repeated A* by preferring smaller g value have reached the target.");
     writer.println(expanded + " cells expanded.");
     writer.println();
   }
   return expanded;
 }
Exemplo n.º 3
0
 public int testAdaptive(PrintWriter writer) {
   int expanded = search.run(cells, true, true, true);
   maze.printMaze("AdaptiveAStar.txt");
   if (expanded == 0) {
     writer.println("Adaptive A* cannot reach the target.");
     writer.println();
   } else {
     writer.println("Adaptive A* have reached the target.");
     writer.println(expanded + " cells expanded.");
     writer.println();
   }
   return expanded;
 }
Exemplo n.º 4
0
 public int runAStar(PrintWriter writer) {
   int expanded = search.run(cells, true, true, false);
   maze.printMaze("RepeatedAStar.txt");
   if (expanded == 0) {
     writer.println("Repeated A* cannot reach the target.");
     writer.println();
   } else {
     writer.println("Repeated A* have reached the target.");
     writer.println(expanded + " cells expanded.");
     writer.println();
   }
   return expanded;
 }
Exemplo n.º 5
0
  public void trace(int p1, int q1, int p2, int q2) {
    // like solve except instead of returning T/F it returns a copy of the maze with the route
    // traced out.
    Deque<Point> stack = new ArrayDeque<Point>();
    HashSet<Point> avoid = new HashSet<Point>();
    // avoid returns points you should NOT try. You've already gone there and exhausted all possible
    // moves.
    // stack.push(new Point(p1,q1));
    stack = solver(new Point(p1, q1), new Point(p2, q2), stack, avoid);

    // now given the stack of solutions, paint the solution on a grid.
    // for each element of the stack, replace that cell in the bitstring with an x
    String outstring = new String(this.bits);
    for (Point point : stack) {
      int p = point.x;
      int q = point.y;
      int i = findIndex(p, q);
      outstring = addRoute(outstring, i);
    }
    printMaze(outstring);
  }