Keep 'em (not) separated: detecting discontinuities in grid graphs

In this post, I'm going to describe how I efficiently detected enclosed spaces in my browser game's map. As the player places obstacles, cells that would create an enclosed space are greyed-out. In Build + Brawl , a free browser game I recently published, enemies march relentlessly towards the player character. To keep them at bay, the player can place impassable obstacles onto the battlefield,…