Untitled
unknown
plain_text
3 years ago
4.0 kB
2
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_obj has all the attributes to help you in in your path planning ! 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 #to identify dead ends pop_intersec = True if (tileNum == 14 or tileNum == 7 or tileNum == 11 or tileNum == 13): pop_intersec = False directions = ['up', 'down', 'left', 'right'] if (notDir != directions[0] and not self.current_obj.map.check_top_wall(current_coords)): self.current_obj.direction_callback(directions[0]) notDir = directions[1] elif (notDir != directions[1] and not self.current_obj.map.check_bottom_wall(current_coords)): self.current_obj.direction_callback(directions[1]) notDir = directions[0] elif (notDir != directions[2] and not self.current_obj.map.check_left_wall(current_coords)): self.current_obj.direction_callback(directions[2]) notDir = directions[3] elif (notDir != directions[3] and not self.current_obj.map.check_right_wall(current_coords)): self.current_obj.direction_callback(directions[3]) notDir = directions[2] while(not pop_intersec): stack.pop() 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()