Example #1
0
 def startDigCorridor(self, start, dir):
     step = (coord.sum(start, dir), coord.sum(start, dir, dir))
     if any([self._map.isOutBound(c) for c in step]): return
     if any([self._map.at(c).isStopDig for c in step]): return
     if any([c in self._diged for c in step]): return
     for c in step:
         self._diged.add(c)
         if self._map.at(c) == Tile.NULL:
             self._map.put(c, Tile.CORRIDOR)
     self.digAround(step[1])
Example #2
0
 def updateExitCanditate(self):
     for w in self._walls():
         if len(
             [d for d in direction.CROSS if coord.sum(w, d) in self._space
              ]) != 1:
             continue
         self._exitCanditate.append(w)
Example #3
0
 def update(self):
   self.render()
   key = self._console.getKey()
   if key in self.KeyMap:
     self._cursor = coord.sum(self._cursor, self.KeyMap.get(key))
   else:
     self.putTerrain(key)
Example #4
0
 def _walls(self):
     walls = set()
     for p in self._space:
         walls |= set([
             w for w in [coord.sum(p, d) for d in direction.CROSS]
             if w not in self._space
         ])
     return walls
Example #5
0
 def flood(self, start, flooded):
     for d in direction.CIRCLE:
         c = coord.sum(start, d)
         if self._isOutBound(c): continue
         if c in self._alives: continue
         if c in flooded: continue
         flooded.add(c)
         self.flood(c, flooded)
     return flooded
Example #6
0
 def toOctant(self, center, octant):
   dx, dy = coord.sub((self.x, self.y), center)
   if octant == 0: return coord.sum(center, (dx, dy))
   if octant == 1: return coord.sum(center, (dy, dx))
   if octant == 2: return coord.sum(center, (-dx, dy))
   if octant == 3: return coord.sum(center, (-dy, dx))
   if octant == 4: return coord.sum(center, (dx, -dy))
   if octant == 5: return coord.sum(center, (dy, -dx))
   if octant == 6: return coord.sum(center, (-dx, -dy))
   if octant == 7: return coord.sum(center, (-dy, -dx))
   raise ValueError("invalid octant")
Example #7
0
 def fillDeadEnd(self, point):
     if not self.isDeadEnd(point): return
     self._map.put(point, Tile.NULL)
     for d in direction.CROSS:
         step = coord.sum(point, d)
         if self._map.at(step).isWall: continue
         self.fillDeadEnd(step)
         break
     for de in self._deadends:
         self._map.put(de, Tile.DEADEND)
Example #8
0
 def moveHero(self, dir):
     nextCoord = coord.sum(self._hero, dir)
     if self._map.isWall(nextCoord): return
     self._hero = nextCoord
Example #9
0
 def isDeadEnd(self, point):
     wall = 0
     for d in direction.CROSS:
         if self._map.at(coord.sum(point, d)).isWall:
             wall += 1
     return wall == 3
Example #10
0
 def around(self):
   return [coord.sum(self._coord, d) for d in direction.CIRCLE]
Example #11
0
 def countLiveNeighbours(self, c):
     alives = 0
     for d in direction.CIRCLE:
         if coord.sum(c, d) in self._alives:
             alives += 1
     return alives
Example #12
0
 def move(self, point):
     self._space = set([coord.sum(point, s) for s in self._space])
     return self
Example #13
0
 def update(self):
     key = self._console.getKey()
     coord.sum(self._coord, Walk.KeyMap.get(key, (0, 0)))
     self.render()
Example #14
0
 def moveTarget(self, dir):
     self._target = coord.sum(self._target, dir)
Example #15
0
 def testMultiSumAndSub(self):
   self.assertEqual(coord.sum((1, 2), (3, 4), (5, 6)), (9, 12))
   self.assertEqual(coord.sub((5, 6), (3, 4), (1, 2)), (1, 0))
Example #16
0
 def testSumAndSub(self):
   self.assertEqual(coord.sum((1, 2), (3, 4)), (4, 6))
   self.assertEqual(coord.sub((3, 4), (1, 2)), (2, 2))