Get the latest tech news

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.

To keep them at bay, the player can place impassable obstacles onto the battlefield, forcing enemies along longer paths and buying time to defeat them. Given free rein in placing these obstacles, the player could avoid the challenge of the game entirely by enclosing their character in an impenetrable box: At a high level, to determine the legality of placing an obstacle in a cell, we can run a flood fill from each of its neighbors and see if each reaches the boundary:

Get the Android app

Or read this on Hacker News

Read more on:

Photo of discontinuities

discontinuities

Photo of grid graphs

grid graphs