summaryrefslogtreecommitdiffstats
path: root/cell.py
diff options
context:
space:
mode:
Diffstat (limited to 'cell.py')
-rw-r--r--cell.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/cell.py b/cell.py
new file mode 100644
index 0000000..eb71cb3
--- /dev/null
+++ b/cell.py
@@ -0,0 +1,47 @@
+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)