from Strategies.strat import PathFindingStrategy from Strategies.path import restore class DFS(PathFindingStrategy): def findPath(self, maze, start, exit): if exit is None: return [], 0 stack = [start] visited = {start} parent = {} while stack: current = stack.pop() if current == exit: break for n in maze.getNeighbors(current): if n not in visited: visited.add(n) parent[n] = current stack.append(n) return restore(parent, start, exit), len(visited)