Example #1
0
 public SlidePuzzle(int width, int height, String puzzle) {
   history = new History();
   this.width = width;
   this.height = height;
   this.puzzle = puzzle;
   correctPuzzle = Util.createAnswerPanel(puzzle);
   distance = new Distance(width, height, correctPuzzle);
   char[][] chars = Util.createBoard(width, height, puzzle);
   board = new Board(width, height, puzzle);
   int distInt = distance.getAllDistance(chars);
   int maxDistInt = distance.getMaxDistance(chars);
   history.putHistory(puzzle, "", distInt, maxDistInt);
   answerBoard = new AnswerBoard();
   answerBoard.put(puzzle, distInt, distance.getMaxDistance(chars));
 }
Example #2
0
  /**
   * * 移動とその距離をhistoryに加える処理。
   *
   * @param operation
   * @param position
   * @param currentDistance
   * @param currentMaxDistance
   */
  private void move(
      String operation, MovedPosition position, int currentDistance, int currentMaxDistance) {
    String boardStr = board.getBoardString();
    char changedChar = position.getC();
    int oldX = position.getOldX();
    int oldY = position.getOldY();
    int newX = position.getNewX();
    int newY = position.getNewY();
    if (history.getOperationHistory(boardStr) == null) {
      char[][] c = Util.createBoard(width, height, boardStr);
      int newDistance =
          distance.getNewDistance(changedChar, oldX, oldY, newX, newY, currentDistance);
      int newMaxDistance = distance.getMaxDistance(c);

      answerBoard.put(boardStr, newDistance, newMaxDistance);
      history.putHistory(boardStr, operation, newDistance, newMaxDistance);
    }
  }