Ejemplo n.º 1
0
  /**
   * Method to get neighbors for a tile
   *
   * @param r
   * @param prevCol
   * @param nextCol
   * @param row
   * @param board
   * @return List<String> consisting of the neighboring tiles
   */
  private List<String> checkNeighbor(String row, String column, Board board) {
    List<String> positions = new ArrayList<>();
    List<String> position = new ArrayList<>();
    int rowIndex = board.getRows().indexOf(row);
    int columnIndex = board.getColumns().indexOf(column);
    if (rowIndex - 1 > 0) {
      position.add(column + board.getRows().get(rowIndex - 1));
      if (board.getBoard().get(column + board.getRows().get(rowIndex - 1)) != null) {
        positions.add(column + board.getRows().get(rowIndex - 1));
      }
    }
    if (rowIndex + 1 < board.getRows().size()) {
      position.add(column + board.getRows().get(rowIndex + 1));
      if (board.getBoard().get(column + board.getRows().get(rowIndex + 1)) != null) {
        positions.add(column + board.getRows().get(rowIndex + 1));
      }
    }
    if (columnIndex - 1 > 0) {
      position.add(board.getColumns().get(columnIndex - 1) + row);
      if (board.getBoard().get(board.getColumns().get(columnIndex - 1) + row) != null) {
        positions.add(board.getColumns().get(columnIndex - 1) + row);
      }
    }
    if (columnIndex + 1 < board.getColumns().size()) {
      position.add(board.getColumns().get(columnIndex + 1) + row);
      if (board.getBoard().get(board.getColumns().get(columnIndex + 1) + row) != null) {
        positions.add(board.getColumns().get(columnIndex + 1) + row);
      }
    }

    return positions;
  }
Ejemplo n.º 2
0
  /**
   * Inspect tile and set type of move in the node.
   *
   * @param board
   * @param row
   * @param column
   * @return
   */
  public String inspect(Board board, String row, String column) {
    ArrayList<String> hotels;
    hotels = new ArrayList<>();

    List<String> neighbors = checkNeighbor(row, column, board);
    for (String n : neighbors) {
      if (!hotels.contains(board.getBoard().get(n).getLabel()))
        hotels.add(board.getBoard().get(n).getLabel());
    }

    if (neighbors.size() > 1) {
      Set<String> set = new HashSet<>(hotels);
      // for (String h : hotels) {
      if (set.size() == 1) {
        if (hotels.get(0).equals(Config.Moves.SINGLETON.getMove())) {
          return Config.Moves.FOUNDING.getMove();
        } else return Config.Moves.GROWING.getMove();
      } else return Config.Moves.MERGING.getMove();
      // }
    } else if (neighbors.size() == 1 && hotels.get(0).equals(Config.Moves.SINGLETON.getMove())) {
      return Config.Moves.FOUNDING.getMove();
    } else if (neighbors.size() == 1 && !hotels.isEmpty()) {
      return Config.Moves.GROWING.getMove();
    } else if (neighbors.size() == 0) {
      return Config.Moves.SINGLETON.getMove();
    }

    return null;
  }