how to tell if fence encloses area

I have a tile grid. I am placing ‘fence’ objects on the grid. I am casting a ray to determine which grid tiles have a fence object on them.

The goal of the game is to surround objects with a fence. Once they are surround then they are “captured”. However I am having trouble coming up with a system that can accurately detect if a gameobject is surrounded by fence objects.

Anyone know how I might be able to do this accurately?

Try a flood fill algorithm, and see if you can reach the edge of the grid.