Packing densities in grid world Suppose there is a 25x50 grid world with 1250 grid cells. Suppose some of them are colored black (full) and some are white (empty). We are interested in quantifying the packing of this grid world. If there are $x$ black cells then the most naive measure of packing is $\frac{x}{1250}$ but this is not too informative because according to it the two packings shown below would be equivalent. But clearly, the first one is relatively more packed than the second one because the second one allows the filled cells to be more spread out.

What are some good quantitative indicators to capture the packing of a grid world? Closed-form formula would be preferred if possible.
 A: First, you should define a "distance function" on your "grid world," since you have made clear that how "packed" an arrangement is depends on how close together the black cells are. Let two black squares be characterized by their horizontal position $x$ and their vertical position $y$. Let $X,Y$ be black squares with coordinates $(x_1,y_1)$ and $(x_2,y_2)$ respectively. You might quantify distance in the traditional Euclidean way with the distance function
$$d(X,Y)=\sqrt{(x_1-x_2)^2+(y_1-y_2)^2}$$
...or, since you are dealing with a grid work, it might better suit your purposes to use the taxicab metric
$$d(X,Y)=|x_1-x_2|+|y_1-y_2|$$
Whatever you decide on, for the purpose of neatness later in this post, I will assume that $d(X,Y)=1$ for two adjacent black squares $X,Y$. 
Anyways, suppose you have settled on a distance function $d(X,Y)$ and you are now ready to try and quantify "packed-ness." There are many ways to do this; but first, let's define some things that will help us evaluate this situation mathematically. 
Suppose that $X$ is a black square on the grid, and define $X_C$ to be a black square on the grid that is closest to $X$. Similarly, let $X_F$ be a black square on the grid that is farthest from $X$. Let $W(X)$ be the number of white squares adjacent (not diagonal) to $X$, and define $B(X)$ analogously for black squares. Furthermore, let $(m,n,G)$ represent the grid world by letting $m,n$ be the dimensions of the world and letting $G$ be the set of blackened squares in the world, denoted by their ordered pairs. Also, define $G'$ to be the set of all ordered pairs in the grid, and denote an arbitrary space in the grid, black or white, by $S\in G'$.
Here are a few proposals for measures of "packed-ness," with advantages and disadvantages described in moderate detail. In each case, the the function $P$ takes as input the grid state and outputs a number between $0$ and $1$, where we would like $0$ to represent an empty grid and $1$ to represent a grid entirely full of black squares.
PROPOSAL 1. We may let
$$P_1=\frac{|G|}{mn}$$
This is the "naive" example you gave. It is perhaps the most obvious option, but as you observed, it assigns the same value to the two example grid worlds you provided, and our intuition tells us that the "packed-ness" measure of the first world should be much higher. So we'll dump this idea.
PROPOSAL 2. Let's try this:
$$P_2=\frac{1}{mn}\sum_{X\in G} d(X,X_C) $$
If there are no black squares in $G$, then this equals $0$ since the sum will be empty. If all squares are black, then each black square will be exactly $1$ distance unit away from the nearest black square (according to my earlier assumption that $d(X,Y)=1$ when $X,Y$ are adjacent), so the sum will equal $|G|=mn$ and the measure will equal $1$. 
In my opinion, this is a pretty good measure, since it takes into account both the packed-ness of the black squares and the proportion of black squares in the grid. However, it is obviously imperfect. It would assign the same packed-ness value to a grid containing four black squares arranged in a $2$ by $2$ block as it would to a grid containing four black squares arranged in a straight line, even though intuition tells us that the former is "more packed."
Another weakness is that this is undefined when there is only one black square in the grid, but you can fix that by assigning it some other value piecewise for that case.
PROPOSAL 3. How about this one:
$$P_3=\frac{\sum_{X\in G} B(X)}{12-5m-5n+4mn}$$
Rather than considering the "closest neighbor" of each black square, this measure takes into account how many neighbors each black square has, but gives no credit for neighbors that are close by but not touching. A bit of combinatorics shows that this is $0$ for an empty board and $1$ for a full board. This solves the problem that the previous measurement had. If we had $4$ black squares in a block, the numerator of this fraction would be $8$, but if we had $4$ black squares in a line, it would only be $6$, which is what we want. 
Unfortunately, as I said, this measure does not take into account neighbors that are close to each other but not adjacent. For example, it would give a value of $0$ to your second example grid world, which surely isn't right.
PROPOSAL 4. Okay, one more try:
$$P_4=\frac{\sum_{X,Y\in G}d(X,Y)^{-1}}{\sum_{S,T\in G'}d(S,T)^{-1}}$$
This is probably the most effective measure to use, since it counts up the distances between every pair of black squares, and doesn't rely only on any single thing like "the closest neighbor," "the farthest neighbor," or "number of immediate neighbors." As we would like, this assigns a null value to an empty grid, a value of $1$ to a full grid, and a value that increases as black squares are more clustered together and decreases as black squares become farther apart. This measurement does not fail for any of the examples mentioned thus far.
However, the weakness of this formula lies in the fact that it will probably be much harder to work with than any of the others because of the gross summation and the probable lack of an explicit formula.

That's all I have for now, but I may add some more proposals later. And keep in mind that you can take a (weighted) arithmetic or geometric mean of any of these measurements to make a new measurement that takes each of the discussed factors into account exactly as much as you want it to.
