Exemple #1
0
 public static List<Box> getBorderBoxes(Board board) {
   return filterBoxes(
       new ArrayList<>(board.getBoxes()),
       box -> {
         return box.getColumn() == 1
             || box.getColumn() == board.getGridSizeX() - 2
             || box.getRow() == 1
             || box.getRow() == board.getGridSizeY() - 2;
       });
 }
Exemple #2
0
 public static boolean isLineAvailableBetweenBoxes(Board board, Box box1, Box box2) {
   if (!areNeighborBoxes(box1, box2)) return false;
   int x = (box1.getColumn() + box2.getColumn()) / 2;
   int y = (box1.getRow() + box2.getRow()) / 2;
   Line line = board.getLineByCoordinate(x, y);
   return line != null && line.getOwner() == null;
 }
Exemple #3
0
  public static List<Box> getSurroundingBoxes(Board board, Box box) {
    int x = box.getColumn();
    int y = box.getRow();

    int surroundingBoxes[][] = {
      {x - 2, y},
      {x + 2, y},
      {x, y - 2},
      {x, y + 2}
    };

    return Arrays.stream(surroundingBoxes)
        .map(coords -> board.getBoxByCoordinate(coords[0], coords[1]))
        .filter(b -> b != null)
        .collect(Collectors.toList());
  }
Exemple #4
0
  public static List<Line> getLinesSurroundingBox(Board board, Box box) {
    int x = box.getColumn();
    int y = box.getRow();

    int surroundingLines[][] = {
      {x - 1, y},
      {x + 1, y},
      {x, y - 1},
      {x, y + 1}
    };

    return Arrays.stream(surroundingLines)
        .map(coords -> board.getLineByCoordinate(coords[0], coords[1]))
        .filter(line -> line != null)
        .collect(Collectors.toList());
  }
Exemple #5
0
 public static Line getRandomAvailableLine(Board board) {
   return getRandomAvailableLine(new ArrayList<>(board.getLines()));
 }
Exemple #6
0
 public static List<Box> filterBoxesWithLineCount(Board board, int numberOfLines) {
   return filterBoxes(
       new ArrayList<>(board.getBoxes()), box -> box.getLineCount() == numberOfLines);
 }