Beispiel #1
0
 def tostring(self):
     d = dict(
             ((2*r, 2*c), v)
             for ((r, c), v) in self.puzzle.data.items())
             
     for (y1, x1), (y2, x2) in self.connections:
         dy = y2-y1
         dx = x2-x1
         
         if dx == 0:
             d[y1+y2, x1+x2] = "|"
         elif dy == 0:
             d[y1+y2, x1+x2] = "-"
         elif dx + dy == 0:
             d[y1+y2, x1+x2] = "/"
         else:
             d[y1+y2, x1+x2] = "\\"
         
     return utils.matrix2str(utils.dict2matrix(d))
Beispiel #2
0
 def parse(self, lines):
     data = parser.parse_grid(lines)
     
     m = utils.dict2matrix(data)
     d = [row[::2] for row in m[::2]]
     
     twist = Twist(len(d), len(d[0]), utils.matrix2dict(d))
     markers = {
         "|": [0, -1, 0, 1],
         "-": [-1, 0, 1, 0],
         "\\": [-1, -1, 1, 1],
         "/": [1, -1, -1, 1]
     }
     
     connections = []
     for (y, x), v in sorted(data.items()):
         if v in markers:
             dx1, dy1, dx2, dy2 = markers[v]
             x1, y1 = (x+dx1)/2, (y+dy1)/2
             x2, y2 = (x+dx2)/2, (y+dy2)/2
             c = (y1, x1), (y2, x2)
             connections.append(c)
            
     return TwistSolution(twist, connections)
Beispiel #3
0
 def tostring(self):
     return utils.matrix2str(utils.dict2matrix(self.data))