A rectangular grid is a graph whose neighbors usually come from four adjacent coordinates. Writing the bounds check once and deciding what makes a cell passable prevents many edge errors. A cell on a one-row board is on both the top and bottom boundary. Holes inside an occupied region still contribute exposed perimeter.
Boundary-seeded search answers which cells can reach outside without launching a search from every cell. A flooding order adds a monotone condition, allowing binary search over the last possible crossing. Bottleneck routes replace addition with a maximum height change. Keys and doors need a larger state: revisiting a junction with another key can open a route that was previously unavailable. Treat the state as the complete information that controls the next legal moves.