# How can I tell if a set of tiles form an enclosure?

I have this tile-based game I've been messing around with and I want to have a way to check if a set of wall tiles make an enclosed space.

Here's some more details: I have a tile map. Each tile has an ID. If you have a set of IDs like so:

0,0,0,0,0
0,1,1,1,0
0,1,2,1,0
0,1,1,1,0
0,0,0,0,0


0 is grass, 1 is wall, and 2 is floor. Assuming these have a spot in a 2d array, how can I find and confirm if whether or not the floor tile is surrounded by walls. This method has to be scalable as well. So if the floor area is 2x2 it would still work.

I've already tried implementing a way to check it, but I failed on my first couple of tries. Any recommendations?

• your question is a bit unclear. Given what you write, I'd check every boundary tile to see if it has a wall, as that's how I understand what a "closed space" is, but you might mean something different Nov 6 '14 at 17:53
• Sounds to me like the classic problem encountered in Maze Solving or Game Of Life algorithms Nov 6 '14 at 18:48