Created
July 1, 2011 20:50
-
-
Save laserbat/1059371 to your computer and use it in GitHub Desktop.
Floodfill
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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