# Determine if area is enclosed

Hello, I am trying to determine if an area of terrain is enclosed by a contiguous set of objects, such as walls. Does anyone have advice on how this might be accomplished? The goal is to determine whether the player built a full set of walls around their castle keep, if they didn't then they effectively lose the round.

Preferably I would like to apply a effect to the enclosed area as well showing what area was successfully protected. I've been wrestling with this problem for over a week and don't seem to be making any headway on how to approach this problem.

Hi. You could set a collider as the "outer" limits of the wall and use a raycast for 360 degrees to see if the ray hits the collider. If it does then that means there's a gap in your wall.

If you want to go further and see which part of the wall was properly guarded you could split the a few colliders rather than just 1 to help you detect different sections of the wall.

If you have a way to know which pieces are next to or near each other that would form this barrier. You could create a graph of all the pieces as they are placed. From there determining if an area was enclosed would be almost as simple as doing a topological sort to detect if the graph is cyclic or not. Using that with a couple of other checks should get you most of what you want.