private static int calculateClusteringScore(int[][] boardArray) {
		 int clusteringScore=0;
	        
	        int[] neighbors = {-1,0,1};
	        
	        for(int i=0;i<boardArray.length;++i) {
	            for(int j=0;j<boardArray.length;++j) {
	                if(boardArray[i][j] == 0) {
	                    continue; //ignore empty cells
	                }
	                
	                //clusteringScore-=boardArray[i][j];
	                
	                //for every pixel find the distance from each neightbors
	                int numOfNeighbors = 0;
	                int sum = 0;
	                for(int k : neighbors) {
	                    int x = i + k;
	                    if(x < 0 || x >= boardArray.length) {
	                        continue;
	                    }
	                    for(int l : neighbors) {
	                        int y = j + l;
	                        if(y < 0 || y >= boardArray.length) {
	                            continue;
	                        }
	                        
	                        if(boardArray[x][y] > 0) {
	                            ++numOfNeighbors;
	                            sum += Math.abs(boardArray[i][j] - boardArray[x][y]);
	                        }
	                        
	                    }
	                }
	                
	                clusteringScore += (sum/numOfNeighbors);
	            }
	        }
	        
	        return clusteringScore;
	}