示例#1
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;
 }
示例#2
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());
  }
示例#3
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());
  }
示例#4
0
 public static boolean areNeighborBoxes(Box box1, Box box2) {
   return (box1.getRow() == box2.getRow() && Math.abs(box1.getColumn() - box2.getColumn()) == 2)
       || (box1.getColumn() == box2.getColumn() && Math.abs(box1.getRow() - box2.getRow()) == 2);
 }