from gm import globaldata class Cell (object): def __init__(self, address): self.address = address self.neighbors = {} h = p = 0 for f in globaldata[address]: if len(f)==3: self.neighbors['h'+str(h)] = f h += 1 else: self.neighbors['p'+str(p)] = f p += 1 if len(self.neighbors)==6: self.type = 'hexagon' else: self.type = 'pentagon' def _templ(self): if self.type == 'hexagon': return self._hex_templ() else: return self._pent_templ() ascii = property(_templ) def __repr__(self): return "Cell %s (%s)" % (self.address, self.type) def _hex_templ(self): panel = """ ____ / \\ / \\ \\ / \\____/ Cell: %s """ % self.address legend = """ Neigboring Pentagons: %(p0)s, %(p1)s, %(p2)s Neigboring Hexagons : %(h0)s, %(h1)s, %(h2)s """ % self.neighbors return panel + legend def _pent_templ(self): panel = """ ____ / \\ \\ / \\ / \\/ Cell: %s """ % self.address legend = """ Neigboring Hexagons : %(h0)s, %(h1)s, %(h2)s, %(h3)s, %(h4)s """ % self.neighbors return panel + legend whichcell = globaldata.keys()[0] looping = True while looping: thecell = Cell(whichcell) print thecell.ascii whichcell = raw_input("Which neighbor? (x=quit): ") if whichcell in 'qxQX': looping = False