Exemplo n.º 1
0
  @Test
  public void solve4x4() {
    final Puzzle puzzle = new Puzzle(4, 4).shuffle(500, 0);

    final Solver solver = new AStarSolver();
    solver.setHeuristic(WalkingDistanceHeuristic.instance());
    final Solution solution = solver.solve(puzzle);

    assertNotNull(solution);
    assertEquals(46, solution.steps());

    System.out.printf(
        "  A*, 4x4, %2s steps, %9s expansions\n", solution.steps(), solver.expansions());
  }
Exemplo n.º 2
0
  @Test
  public void solve3x3Hardest() {
    final Puzzle puzzle = new Puzzle(3).set(8, 7, 6, 0, 4, 1, 2, 5, 3);

    final Solver solver = new AStarSolver();
    solver.setHeuristic(WalkingDistanceHeuristic.instance());
    final Solution solution = solver.solve(puzzle);

    assertNotNull(solution);
    assertEquals(31, solution.steps());

    System.out.printf(
        "  A*, 3x3, %2s steps, %9s expansions\n", solution.steps(), solver.expansions());
  }
Exemplo n.º 3
0
  @Test
  public void solve5x3() {
    final Puzzle puzzle = new Puzzle(5, 3).set(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0);

    final Solver solver = new AStarSolver();
    solver.setHeuristic(WalkingDistanceHeuristic.instance());
    final Solution solution = solver.solve(puzzle);

    assertNotNull(solution);
    assertEquals(42, solution.steps());

    System.out.printf(
        "  A*, 5x3, %2s steps, %9s expansions\n", solution.steps(), solver.expansions());
  }