class Cell(object): row = None column = None links = None north = None south = None east = None west = None def __init__(self, row, column): self.row = row self.column = column self.links = {} def link(self, cell, bidirectional=True): self.links[cell] = True if bidirectional: cell.link(self, bidirectional=False) def unlink(self, cell, bidirectional=True): self.links.pop(cell) if bidirectional: cell.unlink(cell, bidirectional=False) def links(self): return self.links.keys() def is_linked_to(self, cell): return cell in self.links def neighbors(self): n = [] if self.north: n.append(self.north) if self.south: n.append(self.south) if self.east: n.append(self.east) if self.west: n.append(self.west)