Skip to content

Instantly share code, notes, and snippets.

View laserbat's full-sized avatar

Olga Ustiuzhanina laserbat

View GitHub Profile
36089119 function calls (35307177 primitive calls) in 172.299 CPU seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 172.299 172.299 <string>:1(<module>)
380 0.028 0.000 2.611 0.007 AStar.py:139(getPath)
1 0.000 0.000 0.001 0.001 AStar.py:18(<module>)
1 0.000 0.000 0.000 0.000 AStar.py:21(node)
67798 0.111 0.000 0.111 0.000 AStar.py:26(__init__)
def near(self,x1,y1,x2,y2):
"""Checks if x1,y1 near x2,y2"""
if x1 - x2 >= -1 and x1 - x2 <= 1 and\
y1 - y2 >= -1 and y1 - y2 <= 1:
return True
else:
return False
def hasSpaceAround(self,x,y):
"""Checks if there is free cells
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
22377185 function calls (20756598 primitive calls) in 102.934 CPU seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 102.934 102.934 {execfile}
1 0.001 0.001 102.934 102.934 main.py:20(<module>)
1 1.296 1.296 102.909 102.909 Game.py:65(main_loop)
750 0.235 0.000 50.794 0.068 Game.py:651(playerTurn)
272 6.107 0.022 32.549 0.120 Game.py:275(drawmap)
@laserbat
laserbat / gist:1061497
Created July 2, 2011 18:22
hasSpaceAround(x,y)
def hasSpaceAround(x,y):
"""Checks if there is free cells
around x,y"""
global gamemap
c = 0
for x2 in xrange(-2,2):
for y2 in xrange(-2,2):
if near(x, y,x + x2,y + y2):
if not gamemap[x + x2][y + y2].type[0]:
c += 1
def near(x1,y1,x2,y2):
"""Checks if x1,y1 near x2,y2"""
if -1 <= (x1 - x2) <= 1 and -1 <= (y1 - y2) <= 1:
return True
else:
return False
def drawmap(self):
"""Drawmap function.
Will draw map. Working with fov.
"""
global gamemap,screen
global io
mapx,mapy=0,0
for mapx in xrange(MAP_W - 1):
for mapy in xrange(MAP_H - 1):
#If cell is in map range
454 turns.
19482106 function calls (19060266 primitive calls) in 108.624 CPU seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 108.624 108.624 {execfile}
1 0.001 0.001 108.624 108.624 main.py:20(<module>)
1 10.960 10.960 108.602 108.602 Game.py:65(main_loop)
if not random.randint(0,10000) and moremobs:
if gamemap[mapx][mapy].type[0] and not gamemap\
[mapx][mapy].visible and gamemap[mapx][mapy]\
.fval==gamemap[x][y].fval:
gamemap[mapx][mapy] = cell.Newt("Newt",\
":",gamemap[mapx][mapy])
mobs.append((mapx,mapy))
def moveMob(self,x,y,mx,my,gamemap):
"""Moves mob"""
if gamemap[mx][my].type[0] or gamemap[x][y].phasing:
ucell = gamemap[mx][my]
gamemap[mx][my] = gamemap[x][y]
gamemap[x][y] = gamemap[x][y].undercell
gamemap[mx][my].undercell = ucell
gamemap[mx][my].lit = gamemap[mx][my].undercell.lit
gamemap[mx][my].changed = True
gamemap[x][y].changed = True