Skip to content

Instantly share code, notes, and snippets.

@laserbat
Created July 1, 2011 20:50
Show Gist options
  • Save laserbat/1059371 to your computer and use it in GitHub Desktop.
Save laserbat/1059371 to your computer and use it in GitHub Desktop.
Floodfill
def floodFill(self):
"""Floodfills map
for reachability test"""
global gamemap
x = 1
for mapx in xrange(MAP_W - 1,0,-1):
for mapy in xrange(MAP_H,0,-1):
if gamemap[mapx][mapy].type[0] and gamemap[mapx][mapy].fval\
== 0:
xl,yl = mapx,mapy
self.flood(xl,yl,x,0)
x += 1
def flood(self,x,y,v,d):
"""Recursive floodfill function"""
global gamemap
sys.setrecursionlimit(2000)
if gamemap[x][y].type[0] == False or gamemap[x][y].fval == v or\
gamemap[x][y].fval != d:
return 0
if gamemap[x][y].mob:
gamemap[x][y].undercell.fval = v
gamemap[x][y].fval = v
self.flood(x + 1,y,v,d)
self.flood(x + 1,y + 1,v,d)
self.flood(x - 1,y,v,d)
self.flood(x - 1,y - 1,v,d)
self.flood(x,y + 1,v,d)
self.flood(x,y - 1,v,d)
self.flood(x + 1,y - 1,v,d)
self.flood(x - 1,y + 1,v,d)
return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment