develop #1

Open
FirsovAV wants to merge 1141 commits from UNN/2026-rff_mp:develop into develop
4 changed files with 37 additions and 0 deletions
Showing only changes of commit d04a7c0c47 - Show all commits

View File

View File

View File

@ -0,0 +1,23 @@
from strat import PathFindingStrategy
from path import restore
class DFS(PathFindingStrategy):
def find_path(self, maze, start, exit):
stack = [start]
visited = {start}
parent = {}
while start:
current = stack.pop()
if current == exit:
break
for n in maze.get_neighbors(current):
if n not in visited:
visited.add(n)
parent[n] = current
stack.append(n)
return self.restore(parent, start, exit), len(visited)

View File

@ -0,0 +1,14 @@
def restore(self, parent, start, exit):
if exit not in parent and start != exit:
return[]
path = []
current = exit
while current != start:
path.append(current)
current = parent[current]
path.append(start)
path.reverse()
return path