Let $M \in \{0, 1\}^{n \times n}$ be a grid. 0 represents a free field, 1 a blocked field. You can move in four directions: up, down, left, right.
Given the worst possible start and end position on the worst possible $n \times n$ grid, what is the length of the shortest path?
While writing this question, I created a couple of examples and I'm pretty sure I found at least a part of the answer.
uneven $n$
The worst possible grid uses a zig-zag pattern. The start is at lower left and the end at the right. Every second line has $n-1$ blocking elements. There are $\frac{n-1}{2}$ of such lines, leading to $(n-1) \cdot \frac{n-1}{2} = \frac{n^2 -2n + 1}{2}$ blocking elements. We are already at a start position. This means the longest path is the number of remaining elements minus 1:
\begin{align} f(n) &= n^2 - \frac{n^2 -2n + 1}{2} - 1\\ &= \frac{n^2}{2} + n - \frac{3}{2} \end{align}
Some examples:
Simple examples
Example grid:
Example grid:
Even $n$
For even $n$, using the same pattern, one can achieve at least $f(n-1) + (n-1)$. I'm not convinced that this is the maximum, though.
This would give:
Examples
Example grid:
Example $6 \times 6$ grid: 21 steps