Exemplo n.º 1
0
  @Override
  public void solveMazeUser(final String name, final String x, final String y, final String z) {
    int X = new Integer(x);
    int Y = new Integer(y);
    int Z = new Integer(z);
    final String mazenewStart = name + x + y + z;
    Maze3dPosition mazeStartPosition = new Maze3dPosition(X, Y, Z);
    final Maze3d maze = stringtoMaze3d.get(name);
    maze.setStartPosition(mazeStartPosition);
    stringtoMaze3d.put(mazenewStart, maze);
    if (solutionMap.containsKey(maze)) {
      this.modelCompletedCommand = 9;
      this.setData(mazenewStart);
      setChanged();
      notifyObservers();
    } else {

      Future<Solution<Position>> f =
          c.submit(
              new Callable<Solution<Position>>() {
                @SuppressWarnings({"unchecked", "rawtypes"})
                @Override
                public Solution<Position> call() throws Exception {
                  Searchable<Position> s = new Maze3dSearch(maze);
                  Maze3DSolution solution = new Maze3DSolution();
                  if (p.getDefSolver().equals("bfs")) {
                    System.out.println("Solve with defualt bfs");
                    BfsCommonSearcher Bfs = new BfsCommonSearcher(solution);
                    Bfs.setSolution(solution);
                    // solveMazeByBfs(mazenewStart);
                    return (Maze3DSolution) Bfs.Search(s);
                  } else if (p.getDefSolver().equals("astar")) {
                    try {
                      System.out.println("solve with default astar, Manhetthen distance");
                      Manhattandistance h2 = new Manhattandistance();
                      AstarCommonSearcher Astar = new AstarCommonSearcher(h2, solution, s);
                      Astar.setSolution(solution);
                      System.err.println(solution.toString());
                      return (Maze3DSolution) Astar.Search(s);
                    } catch (Exception e) {
                      errorNoticeToController(e.getMessage());
                      e.printStackTrace();
                    }
                  }
                  return solution;
                }
              });
      try {
        solutionMap.put(maze, f.get());
        solveMazeByAstar(mazenewStart);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ExecutionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }