-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNodeSimulator.py
83 lines (67 loc) · 1.87 KB
/
NodeSimulator.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
76
77
78
79
80
81
82
83
class DoubleNode:
def __init__(self, x, y, pastNode=None, head=None):
self.x = x
self.y = y
self.pastNode = pastNode
if(head == None and pastNode != None):
self.head = pastNode.head
else:
self.head = head
def __str__(self):
return f"{self.x}{self.y}"
def gotCut(nodeCut):
cut = []
cut.append([nodeCut.x, nodeCut.y])
nodeCut = nodeCut.pastNode
cut.append(nodeCut)
return cut
def cutBack(node):
cut = []
curX = node.x
curY = node.y
reset = False
if(curX == node.head.x and curY == node.head.y):
reset = True
# cut.append([curX, curY])
cur = node.pastNode
cut.append([cur.x, cur.y])
while(cur.x != curX or cur.y != curY):
cur = cur.pastNode
cut.append([cur.x, cur.y])
cut.pop(-1)
cut.append(cur)
return cut
currentNode = DoubleNode(0, 0)
head = currentNode
print(head)
currentNode = DoubleNode(1, 0, currentNode, head)
currentNode = DoubleNode(2, 0, currentNode)
currentNode = DoubleNode(3, 0, currentNode)
currentNode = DoubleNode(3, 1, currentNode)
currentNode = DoubleNode(3, 2, currentNode)
currentNode = DoubleNode(3, 3, currentNode)
newNode = DoubleNode(3, 4)
newNode = DoubleNode(3, 3, newNode)
arr = gotCut(newNode)
newNode = arr[-1]
arr.pop(-1)
print(newNode)
print(arr)
# currentNode = DoubleNode(2, 3, currentNode)
# currentNode = DoubleNode(1, 3, currentNode)
# currentNode = DoubleNode(1, 2, currentNode)
# currentNode = DoubleNode(1, 1, currentNode)
# currentNode = DoubleNode(1, 0, currentNode)
# currentNode = DoubleNode(0, 0, currentNode)
# arr = cutBack(currentNode)
# currentNode = arr[-1]
# arr.pop(-1)
# print(arr)
# print(currentNode)
# print(head)
# print(currentNode.pastNode)
colors = [(255, 0, 0), (100, 125, 200)]
nodesDict = {}
for i in colors:
nodesDict.update({i:None})
print(nodesDict)