-
Notifications
You must be signed in to change notification settings - Fork 0
/
path.py
150 lines (119 loc) · 3.89 KB
/
path.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
from random import randint
class Node:
def __init__(self, x1, y1):
self.x = x1
self.y = y1
self.t_l = 0
self.t_f = 0
self.t_r = 0
self.t_b = 0
self.front = None
self.back = None
self.left = None
self.right = None
self.next = None
self.vertex = 0
class LinkedList:
def __init__(self):
self.head = None
self.end = None
self.slist = []
self.temp = 0
self.countnode = 1
self.vertexcount = 0
def append(self, x1, y1, t1, *sdata):
new_node = Node(x1,y1)
print(hex(id(new_node)))
sdata = list(sdata)
self.countnode = 1
new_node.vertex = self.vertexcount
self.vertexcount += 1
# Conditions to take the decision for the robot wheather to go LEFT, FRONT, RIGHT
if(sdata.count(1) > 2):
if(sdata[1] == 1 and sdata[3] == 1 and sdata[4] == 0):
guess = randint(1,2)
if(guess == 1):
sdata[1] = 0
elif(guess == 2):
sdata[3] = 0
elif(sdata[1] == 1 and sdata[4] == 1 and sdata[3] == 0):
guess = randint(1,2)
if(guess == 1):
sdata[1] = 0
elif(guess == 2):
sdata[4] = 0
elif(sdata[1] == 1 and sdata[3] == 1 and sdata[4] == 1):
guess = randint(1,3)
if(guess == 1):
sdata[1] = 0
sdata[4] = 0
elif(guess == 2):
sdata[3] = 0
sdata[4] = 0
elif(guess == 3):
sdata[1] = 0
sdata[3] = 0
print(sdata)
# <!----------------------------------------------------------------------------------------!>
if(self.temp == 0):
self.slist = sdata
self.temp = 1
else:
if(self.slist[1] == 1 and self.slist[3] == 0 and self.slist[4] == 0):
new_node.back = self.end # mapping addresses between current and previous node
self.end.front = new_node # mapping addresses between current and previous node
self.slist = sdata
new_node.t_f = t1 # To set time taken to visit next front node
elif(self.slist[4] == 1 and self.slist[1] == 0 and self.slist[3] == 0):
new_node.back = self.end # mapping addresses between current and previous node
self.end.right = new_node # mapping addresses between current and previous node
self.slist = sdata
new_node.t_r = t1 # To set time taken to visit next right node
elif(self.slist[3] == 1 and self.slist[1] == 0 and self.slist[4] == 0):
new_node.back = self.end # mapping addresses between current and previous node
self.end.left = new_node # mapping addresses between current and previous node
self.slist = sdata
new_node.t_l = t1 # To set time taken to visit next left node
# print(self.slist)
if self.head is None: # To set pointer to First Node
self.head = new_node
self.end = new_node
# print(hex(id(self.end)))
return
last = self.head
while last.next:
last = last.next
last.next = new_node
self.end = new_node
# print(hex(id(self.end)))
# print(self.end.x)
# print(hex(id(new_node.left)))
checknode = self.head
while checknode.next:
if(abs(x1 - checknode.x) < 0.05 and abs(y1 - checknode.y) < 0.05):
print("Oouch! we already came to this node, This is node - {0}".format(self.countnode))
self.countnode+=1
checknode = checknode.next
def atPos(self, x1, y1, t1, pos):
# new_node = Node(x1,y1,t1)
move = self.head
for i in range(1,pos):
move = move.next
move.x = x1
move.y = y1
move.t = t1
def printList(self):
temp = self.head
while (temp):
print('node - {0} : {1} {2} {3} {4} {5} {6}'.format(temp.vertex, temp.x, temp.y,
hex(id(temp.left)), hex(id(temp.front)), hex(id(temp.right)), hex(id(temp.back))))
print( "Time Taken :")
print('{0} {1} {2} {3}'.format(temp.t_l,temp.t_f,temp.t_r,temp.t_b))
temp = temp.next
if(__name__ == '__main__'):
llist = LinkedList()
llist.append(1,2,0.1,0,0,0,0,1,0,1,0)
llist.append(3,6,0.2,0,0,0,1,0,0,1,0)
llist.append(3.03,6.04,0.3,0,1,0,1,1,0,1,0)
# llist.atPos(10,30,1.1,2)
llist.printList()