from collections import deque from strategies.pathfinding_strategy import PathFindingStrategy class BFSStrategy(PathFindingStrategy): name = "BFS" def findPath(self, maze, start, exitCell): self.visitedCount = 0 if start is None or exitCell is None: return [] queue = deque([start]) visited = {(start.x, start.y)} parent = {} while queue: current = queue.popleft() self.visitedCount += 1 if current.x == exitCell.x and current.y == exitCell.y: return self._restore_path(parent, start, exitCell) for neighbor in maze.getNeighbors(current): pos = (neighbor.x, neighbor.y) if pos not in visited: visited.add(pos) parent[pos] = current queue.append(neighbor) return []