-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode.py
75 lines (61 loc) · 1.53 KB
/
node.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from colors import WHITE, BLACK, GREEN, RED, YELLOW, LTYELLOW, LIGHT
# Parent class
class Node:
def __init__(self):
self.up = None
self.dn = None
self.left = None
self.right = None
self.color = RED
# Black square class
class BlackNode(Node):
def __init__(self):
Node.__init__(self)
self.color = BLACK
def __str__(self):
return 'B'
# Black square with number
class NumberedNode(Node):
def __init__(self,num=0):
Node.__init__(self)
self.value = num
self.color = GREEN
def __str__(self):
return f'{self.value}'
# Playable space
class WhiteNode(Node):
def __init__(self):
Node.__init__(self)
self.lightConflict = 0
self.color = WHITE
def switchOff(self):
self.color = WHITE
"""
head = self.left
self.switchOffTraverse(head, goLeft)
head = self.right
self.switchOffTraverse(head, goRight)
head = self.dn
self.switchOffTraverse(head, goDown)
head = self.up
self.switchOffTraverse(head, goUp)
"""
# next = function that returns next (up,dn,lft,rt) link
def switchOffTraverse(self, head, next):
queue = []
while head is not None:
if head.color == LTYELLOW:
head.color = WHITE
elif head.color == LIGHT:
head.color = WHITE
queue.append(head)
elif head.color != BLACK:
head = None
elif head.color != GREEN:
head = None
if head != None:
head = next(head)
for n in queue:
n.switchOn()
def __str__(self):
return 'W'