Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
4.1 kB
1
Indexable
Never
from asyncio.windows_events import NULL
import sys

from MapNode import MapNode

class PlannerNode:
    
    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")
        
        self.wall_callback()
        
    

    def wall_callback(self):
        self.current_obj.direction_callback("down")
        
        print(self.current_obj.current)
        # current_obj has all the attributes to help you in in your path planning !
         
        stack = []
        notDir = NULL
        
        current_coords = self.current_obj.current 
           
        stack.append(current_coords)

        tileNum = self.current_obj.array[current_coords[0]][current_coords[1]]
                #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[0]

        if (notDir != directions[1] and not self.current_obj.__map.check_bottom_wall(current_coords)):
            self.current_obj.direction_callback(directions[1])
            notDir = directions[1]

        if (notDir != directions[2] and not self.current_obj.__map.check_left_wall(current_coords)):
            self.current_obj.direction_callback(directions[2])
            notDir = directions[2]

        if (notDir != directions[3] and not self.current_obj.__map.check_right_wall(current_coords)):
            self.current_obj.direction_callback(directions[3])
            notDir = directions[3]

        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'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 5 and notDir != 'down'):
                notDir = 'down'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 3 and notDir != 'down'):
                notDir = 'down'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 3 and notDir != 'right'):
                notDir = 'right'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 12 and notDir != 'left'):
                notDir = 'left'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 12 and notDir != 'up'):
                notDir = 'up'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 10 and notDir != 'up'):
                notDir = 'up'
            if (self.current_obj.array[current_coords[0]][current_coords[1]] == 10 and notDir != 'right'):
                notDir = 'right'
            if (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 

        

                              
         
           





           



            


            
        


         
        

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