Example #1
0
 /**
  * Rewards tiles based on how many neighbours are not of the same type
  *
  * @return int, in range 0 to 6
  */
 public int emptyMultiplier() {
   int count = 0;
   for (Tile t : getAdjacent()) {
     if (t.getPiece() != this.getPiece()) {
       count++;
     }
   }
   return count;
 }
Example #2
0
  /**
   * Helper function - works out the tiles that are adjacent to the current tile (for structure
   * traversal).
   *
   * @return ArrayList of Tiles that are adjacent to the current tile
   */
  public ArrayList<Tile> getAdjacent() {
    ArrayList<Tile> list = new ArrayList<Tile>();

    // Offsets of each neighboring tile (y, x) form
    /*   (y - 1, x - 1)   (y - 1, x)
     *
     * (y, x - 1)   (y, x)  (y, x + 1)
     *
     *      (y+1, x)    (y + 1, x + 1)
     */
    int[][] offsets = {{-1, -1}, {0, -1}, {-1, 0}, {1, 0}, {0, 1}, {1, 1}};

    // make a Tile for each offset
    for (int[] offset : offsets) {
      Tile tile = new Tile(y + offset[0], x + offset[1], board);
      // Check if tile is valid. If it is, add it
      if (tile.isValid()) list.add(tile);
    }

    // Return complete list of adjacent tiles.
    return list;
  }