# Untitled

unknown
plain_text
2 years ago
7.8 kB
4
Indexable
Never
```# 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
#         self.current_obj.direction_callback("down")
#         notDir = None
#         self.stack = []

#         self.wall_callback(notDir)

#     def wall_callback(self, notDir):

#         print(self.current_obj.current)

#         current_coords = self.current_obj.current

#         self.stack.append(current_coords)

#         tileNum = self.current_obj.array[current_coords[0]][current_coords[1]]
#         print(tileNum)
#                 #tileNum is being accessed for the current coord only, which is inline with the practical scenario
#                 #that only the current tile can be seen

#         pop_intersec = True
#         if (tileNum == 14 or tileNum == 7 or tileNum == 11 or tileNum == 13):
#             pop_intersec = False
#             if (tileNum == 14):
#                 notDir = 'right'
#             if (tileNum == 7):
#                 notDir = 'up'
#             if (tileNum == 11):
#                 notDir = 'left'
#             if (tileNum == 13):
#                 notDir = 'down'

#         directions = ['down', 'up', 'left', 'right']

#         if (notDir != directions[0] and not self.current_obj.map.check_bottom_wall(current_coords) and not (current_coords[0]+1, current_coords[1]) in self.stack):
#             self.current_obj.direction_callback(directions[0])
#             notDir = directions[1]
#             self.wall_callback(notDir)

#         elif (notDir != directions[1] and not self.current_obj.map.check_top_wall(current_coords) and not (current_coords[0]-1, current_coords[1]) in self.stack):
#             self.current_obj.direction_callback(directions[1])
#             notDir = directions[0]
#             self.wall_callback(notDir)

#         elif (notDir != directions[2] and not self.current_obj.map.check_left_wall(current_coords) and not (current_coords[0], current_coords[1]-1) in self.stack):
#             self.current_obj.direction_callback(directions[2])
#             notDir = directions[3]
#             self.wall_callback(notDir)

#         elif (notDir != directions[3] and not self.current_obj.map.check_right_wall(current_coords) and not (current_coords[0], current_coords[1]+1) in self.stack):
#             self.current_obj.direction_callback(directions[3])
#             notDir = directions[2]
#             self.wall_callback(notDir)

#         else:
#             self.current_obj.direction_callback(notDir)

#         while(not pop_intersec):
#             print('execute')

#             self.current_obj.direction_callback(notDir)
#             if (self.current_obj.array[current_coords[0]][current_coords[1]] == 5 and notDir != 'left'):
#                 notDir = 'left'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 5 and notDir != 'down'):
#                 notDir = 'down'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 3 and notDir != 'down'):
#                 notDir = 'down'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 3 and notDir != 'right'):
#                 notDir = 'right'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 12 and notDir != 'left'):
#                 notDir = 'left'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 12 and notDir != 'up'):
#                 notDir = 'up'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 10 and notDir != 'up'):
#                 notDir = 'up'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 10 and notDir != 'right'):
#                 notDir = 'right'
#             elif (self.current_obj.array[current_coords[0]][current_coords[1]] == 8 or self.current_obj.array[current_coords[0]][current_coords[1]] == 4 or self.current_obj.array[current_coords[0]][current_coords[1]] == 2 or self.current_obj.array[current_coords[0]][current_coords[1]] == 1 or self.current_obj.array[current_coords[0]][current_coords[1]] ==0):
#                 pop_intersec = True

#         self.wall_callback(notDir)

# if __name__ == '__main__':
#     start_obj=PlannerNode()
#     start_obj.current_obj.print_root.mainloop()

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 = ['up', 'down', 'left', 'right']
self.found = False
self.wall_callback(notDir)

def wall_callback(self, notDir):
current_coords = self.current_obj.current
tileNum = self.current_obj.array[current_coords[0]][current_coords[1]]
print(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 and self.dead))):
self.current_obj.direction_callback(self.directions[0])
self.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 and self.dead))):
self.current_obj.direction_callback(self.directions[1])
self.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 and self.dead))):
self.current_obj.direction_callback(self.directions[2])
self.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 and self.dead))):
self.current_obj.direction_callback(self.directions[3])
self.wall_callback(self.directions[2])
if(self.found):
return

self.stack.pop()
if (tileNum == 14 or tileNum == 7 or tileNum == 11 or tileNum == 13):