Batched checking if 2D image is connected

I am trying to create a vectorized 2D game with an initial phase where the player places 1’s into a 2D zero tensor (with a batch dimension). The ones indicate the presence of a wall at that square.
We start with an empty zero tensor, which is obviously one path-connected-component, if we take movement to be one step in the x or y direction.
With each placement of a wall we have to verify that we did not disconnect the space defined by the zeros in the image.
Does anyone have any idea how this might be achieved in an efficient (batched) way?

I just realized that I can use repeated convolutions with a filter that looks like:
0 1 0
1 0 1
0 1 0
and zeroing out any activations on a wall square
after placing a single 1. on a walkable square