-
Notifications
You must be signed in to change notification settings - Fork 1
/
pyramid.py
38 lines (32 loc) · 1.1 KB
/
pyramid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from param import G
from error import SimulationError
class Pyramid(object):
def __init__(self, id):
self.id = id
self.settled = False
self.pos = self.getPos();
self.x = self.pos[0]
self.y = self.pos[1]
if G.verbose:
print >> G.outfile, "deterministic ant %d is moving" % (self.id)
def getPos(self):
y = -1
blocks = -1
while blocks < self.id:
y += 1
numBlocksOnLine = self.lineWidth(y)
if numBlocksOnLine <= 0:
raise SimulationError("PyramidHeightError", "Pyramid cannot grow higher at current width")
blocks += numBlocksOnLine
xStart = (G.numBlocksX - numBlocksOnLine) / 2
xEnd = G.numBlocksX - xStart
x = xEnd - (blocks - self.id) -1
assert x >= xStart and x < xEnd
return (x,y)
def lineWidth(self, y):
scale = (1 / (G.pyramidScaleFactor * float(y)*float(y) + 1))
ret = float(G.numBlocksX) * scale
return int(ret)
def move(self):
G.state[self.pos] = G.NORMAL
self.settled = True