forked from UNN/2026-rff_mp
25 lines
652 B
Python
25 lines
652 B
Python
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) |