summaryrefslogtreecommitdiffstats
path: root/cell.py
blob: eb71cb3e3709631f48fd7e4a54df9f90399ef634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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)