# Battleship Combinatorics

Imagine a 10x10 battleship grid that we are going to place a 1x5 or 5x1 ship on.

I want to consider the probability distribution for a square containing a ship which I'd then like to plot using software.

Essentially this should look kind of like a discrete Gaussian since

1, the corner squares have very low probability since there are only two possible ships that could touch these squares.

2, on the other hand the squares in the middle will be covered by a large number of ships. For example, square (5,5) seems to have 5 possible vertical and 5 possible horizontal ships if you draw it out. This is also true for squares (5,6), (6,5), (6,6).

In principle, for a 10x10 grid with a ship of length 5, I could conceive going through all 100 squares and explicitly counting the possible ship arrangements.

How would this generalise to an nxn grid with a ship of length m?

• Yep, you're right. I've edited. Thanks. – user11128 Sep 8 at 21:34

The number of different ship positions that go through a given cell is the number of vertical ships plus the number of horizontal ships. So I will focus on the horizontal part, and the vertical part should be completely analogous.

Given that a row has $$n$$ squares, and our ship is of length $$m$$ (assuming $$m\leq n$$), say we are interested in the number of horizontal ship positions that go through cell number $$k$$ in that row. By "default", that's $$m$$. However, if we are too close to the edge (either because $$k$$ is small, or because $$n-k$$ is small), then we lose possibilities.

Specifically, if $$k, then of those $$m$$ positions we lose $$m-k$$ possibilities because we can't go past the left edge. And if $$n-k, then we lose $$k+m-n$$ of the $$m$$ possibilities because we can't go past the right edge.

So in the end it looks like this: $$\text{Horizontal ships through cell k} = \cases{ k & if kn-m\\ m & otherwise}$$ You're thinking of it like a Gaussian, but it's actually an isosceles trapezium. Once you add together rows and vertices, the shape becomes a bit more complicated, but all edges and faces are straight and flat, and it's more pyramid-like than Gaussian-like.

• Yeah that's actually annoyingly straightforward. Thanks! – user11128 Sep 8 at 21:53
• I think it's a bit more complicated than just a truncated pyramid, because you have vertical "discretized trapezoidal" faces on each edge of the base square, and in each corner you have facet where the "gradient" is parallel to a diagonal of the square. – David K Sep 8 at 22:04
• @DavidK Yes, of course. I changed the description. – Arthur Sep 8 at 22:08