-
Notifications
You must be signed in to change notification settings - Fork 2
/
cell.py
59 lines (46 loc) · 1.49 KB
/
cell.py
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
48
49
50
51
52
53
54
55
56
57
58
59
import svgwrite
from distances import Distances
class Cell:
def __init__(self, row, column):
self.row, self.column = row, column
self.links = {}
self.distance = 0
def link(self, cell, bidi=True):
self.links[cell] = True
if bidi:
cell.link(self, False)
def unlink(self, cell, bidi = True):
if cell in self.links:
del self.links[cell]
if bidi: cell.unlink(self, False)
def show_links(self):
print (self.links)
def get_links(self):
return self.links.keys()
def get_links_full(self):
return self.links
def linked(self, cell):
if cell in self.links:
return True
return False
def neighbors(self):
list = []
if self.north: list.append(self.north)
if self.south: list.append(self.south)
if self.west: list.append(self.west)
if self.east: list.append(self.east)
return list
def distances(self):
distances = Distances(self)
frontier = [self]
while len(frontier) > 0:
new_frontier = []
for cell in frontier:
for link in cell.get_links():
if not link in distances.cells:
distances.cells[link] = distances.cells[cell] + 1
new_frontier.append(link)
frontier = new_frontier
return distances
def set_distance(self, distance):
self.distance = distance