예제 #1
0
 public int getValue(int tilesPerRow) {
   // Calculate what speed to return depending on board size and tiles per row.
   int speed =
       (int)
           Math.round(
               (NPuzzle.getSettings().getCurrWindowSize().getBOARD_SIZE() / tilesPerRow)
                   / this.stepsPerMove);
   // If speed is set to 0 because of rounding, tell it to be 1 instead.
   return (speed == 0) ? 1 : speed;
 }
예제 #2
0
 public int getValue() {
   return getValue(NPuzzle.getSettings().getTilesPerRowInBoard());
 }
예제 #3
0
  // Returns a list of movements required to randomize the current board.
  public LinkedList<Move> generateRandomizingMoveSequence() {
    LinkedList<Move> moveSequence = new LinkedList<Move>();
    Point empty = emptyTile;

    int difficulty = NPuzzle.getSettings().getDifficulty();
    // If the board is larger than 8, the difficulty shouldn't be linear. Only if difficulty is
    // easy.
    if (tilesPerRow > 8 && difficulty != Difficulty.EASY.getValue()) {
      difficulty += 1 + (tilesPerRow % 10);
    }

    // Create queue of places to visit
    Stack<Point> placesToVisit = new Stack<>();

    int size = tilesPerRow - 1;
    int quarterSize = size / 4;

    // Calculate x and y points for all corners, center of quadrants and center of board.
    Point center = new Point(size / 2, size / 2);
    Point upperLeftCorner = new Point(0, 0);
    Point upperRightCorner = new Point(size, 0);
    Point lowerLeftCorner = new Point(0, size);
    Point lowerRightCorner = new Point(size, size);
    Point secondQuadrant = new Point(quarterSize, quarterSize);
    Point thirdQuadrant = new Point(quarterSize, size - quarterSize);
    Point fourthQuadrant = new Point(size - quarterSize, size - quarterSize);
    Point firstQuadrant = new Point(size - quarterSize, quarterSize);

    // Make a list of all those points.
    Point[] points = {
      center,
      upperLeftCorner,
      upperRightCorner,
      lowerLeftCorner,
      lowerRightCorner,
      secondQuadrant,
      thirdQuadrant,
      fourthQuadrant,
      firstQuadrant
    };

    // For difficulty add the points a number of times.
    for (int i = 0; i < difficulty; i++) {
      // Shuffle the list and then add all the points to the visitStack.
      Collections.shuffle(Arrays.asList(points));

      for (Point point : points) {
        placesToVisit.push(point);
      }
    }

    // Visit each place in the visitStack and on each place make a lot of random moves in the area
    // around the point.
    Point next;
    while (!placesToVisit.isEmpty()) {
      next = placesToVisit.pop();
      moveEmptyTo(next, empty, moveSequence);
      int areaSizeToRandomize = difficulty * difficulty;
      // If the board is bigger than 25, it needs to make more moves unless difficulty is easy.
      if (tilesPerRow > 25 && difficulty != Difficulty.EASY.getValue()) {
        areaSizeToRandomize *= difficulty;
      }
      generateRandomMovesInCloseArea(moveSequence, empty, areaSizeToRandomize);
    }
    return moveSequence;
  }