'The AI that i coded for my pacman game just crashes my game, it goes through vsc fine without errors so i dont know what is wrong

it is supposed to be a breadth first search, target is the players position. I suspect that a problem could be on the second line of the get_djikstra function but i dont know since the ide isnt telling me much.

def get_djikstra(self, target):
        nextnode = self.findnextnode(target)
        xdir = nextnode[0] - self.grid_pos[0]
        ydir = nextnode[1] - self.grid_pos[1]
        return vec(xdir, ydir)

    def findnextnode(self, target):
        path = self.djikstra([int(self.grid_pos.x), int(self.grid_pos.y)], [int(target.x), int(target.y)])
        return path[1]


    def djikstra(self, start, target):
        grid = [[0 for x in range(30)] for x in range(40)]
        for node in self.RPMGame.walls:
            if node.x <30 and node.y <40:
                grid[int(node.y)][int(node.x)] = 1
        ##removing walls from search above##
        queue = [start]
        path = []
        visited = []
        while queue:
            current = queue[0]
            queue.remove(queue[0])
            visited.append(current)
            if current == target:
                break
            else:
                neighbours = [[0, 1],[1, 0],[-1,0],[0, -1]]
                for neighbour in neighbours:
                    if neighbour[0]+current[0] >= 0 and neighbour[0] + current[0] <len(grid[0]):
                        if neighbour[1]+current[1] >= 0 and neighbour[1] + current[1] <len(grid[0]):
                            nextnode = [neighbour[0] + current[0], neighbour[1] + current[1]]
                            if nextnode not in visited:
                                if grid[nextnode[1]][nextnode[0]] != 1: #if not a wall then append#
                                    queue.append(nextnode)
                                    path.append({"Current": current, "next": nextnode}) ###dictionary##

        shortest = [target]
        while target != start:
            for step in path:
                if step["Next"] == target:
                    target = step["Current"]
                    shortest.insert(0, step["Current"])

        return shortest


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source