-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlannerNode.py
68 lines (47 loc) · 2.44 KB
/
PlannerNode.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
from asyncio.windows_events import NULL
import sys
from MapNode import MapNode
class PlannerNode:
stack = []
def __init__(self):
self.current_obj=MapNode()
# Since we know that the first step the bot will take will be down, we can simply do it here
self.current_obj.direction_callback("down") # example 1
notDir = 'up'
self.stack = []
self.directions = ['down', 'left', 'right', 'up']
self.found = False
self.wall_callback(notDir)
def wall_callback(self, notDir):
print(self.current_obj.current)
# current_obj has all the attributes to help you in in your path planning !
current_coords = self.current_obj.current
self.stack.append(current_coords)
if(current_coords == self.current_obj.map.end):
self.found = True
return
if (notDir != self.directions[0] and not self.current_obj.map.check_top_wall(current_coords) and ((current_coords[0] - 1, current_coords[1]) not in self.stack)):
self.current_obj.direction_callback(self.directions[0])
wall_callback(self.directions[1])
if(self.found):
return
if (notDir != self.directions[1] and not self.current_obj.map.check_bottom_wall(current_coords) and ((current_coords[0] + 1, current_coords[1]) not in self.stack)):
self.current_obj.direction_callback(self.directions[1])
wall_callback(self.directions[0])
if(self.found):
return
if (notDir != self.directions[2] and not self.current_obj.map.check_left_wall(current_coords) and ((current_coords[0], current_coords[1] - 1) not in self.stack)):
self.current_obj.direction_callback(self.directions[2])
wall_callback(self.directions[3])
if(self.found):
return
if (notDir != self.directions[3] and not self.current_obj.map.check_right_wall(current_coords) and ((current_coords[0], current_coords[1] + 1) not in self.stack)):
self.current_obj.direction_callback(self.directions[3])
wall_callback(self.directions[2])
if(self.found):
return
stack.pop()
self.current_obj.direction_callback(notDir)
if __name__ == '__main__':
start_obj=PlannerNode()
start_obj.current_obj.print_root.mainloop()