private int mergeMovementsAvailable(){
  final AtomicInteger pairsOfMergeableTiles=new AtomicInteger();
  int cont=0;
  Direction direction=Direction.UP;
  do {
    for (    Integer x : gridOperator.getTraverseX()) {
      for (      Integer y : gridOperator.getTraverseY()) {
        Location thisloc=new Location(x,y);
        Tile tile=gameGrid.get(thisloc);
        if (tile != null) {
          Tile offsetTile=gameGrid.get(thisloc.offset(direction));
          if (offsetTile != null && tile.isMergeable(offsetTile)) {
            pairsOfMergeableTiles.incrementAndGet();
          }
        }
      }
    }
    direction=Direction.LEFT;
    cont++;
  }
 while (cont < 2);
  return pairsOfMergeableTiles.get();
}

private int mergeMovementsAvailable ( ) { final AtomicInteger pairsOfMergeableTiles = new AtomicInteger ( ) ; int cont = 0 ; Direction direction = Direction . UP ; do { for ( Integer x : gridOperator . getTraverseX ( ) ) { for ( Integer y : gridOperator . getTraverseY ( ) ) { Location thisloc = new Location ( x , y ) ; Tile tile = gameGrid . get ( thisloc ) ; if ( tile != null ) { Tile offsetTile = gameGrid . get ( thisloc . offset ( direction ) ) ; if ( offsetTile != null && tile . isMergeable ( offsetTile ) ) { pairsOfMergeableTiles . incrementAndGet ( ) ; } } } } direction = Direction . LEFT ; cont ++ ; } while ( cont < 2 ) ; return pairsOfMergeableTiles . get ( ) ; }
finds the number of pairs of tiles that can be merged this method is called only when the grid is full of tiles , what makes the use of optional unnecessary , but it could be used when the board is not full to find the number of pairs of mergeable tiles and provide a hint for the user , for instance
