2026-05-20 18:42:45 +00:00
|
|
|
from source.strategy.strategy import PathFindingStrategy
|
|
|
|
|
from source.classes.maze import Maze
|
|
|
|
|
from source.classes.cell import Cell
|
|
|
|
|
|
|
|
|
|
class DFS(PathFindingStrategy):
|
2026-05-20 20:07:51 +00:00
|
|
|
def findPath(self, maze: Maze):
|
2026-05-20 18:42:45 +00:00
|
|
|
pass
|
2026-05-20 20:07:51 +00:00
|
|
|
def name(self):
|
|
|
|
|
return "DFS"
|
2026-05-20 18:42:45 +00:00
|
|
|
|
2026-05-20 20:07:51 +00:00
|
|
|
def __dfs__(self, maze: Maze):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# public static Cell SearchInDepth(Cell entry, Cell target)
|
|
|
|
|
# {
|
|
|
|
|
# Dictionary<int, Cell> visited = new Dictionary<int, Cell>();
|
|
|
|
|
# Stack<Cell> toVisit = new Stack<Cell>();
|
|
|
|
|
# entry.DistanceLeft = (target.Position - entry.Position).magnitude;
|
|
|
|
|
# toVisit.Push(entry);
|
|
|
|
|
# visualise(target, VisualAction.Target);
|
|
|
|
|
# visualise(entry, VisualAction.ToVisit);
|
|
|
|
|
|
|
|
|
|
# while (toVisit.Count > 0)
|
|
|
|
|
# {
|
|
|
|
|
# Cell current = toVisit.Pop();
|
|
|
|
|
# visualise(current, VisualAction.Visiting);
|
|
|
|
|
# if (current.Equals(target))
|
|
|
|
|
# {
|
|
|
|
|
# return current;
|
|
|
|
|
# }
|
|
|
|
|
# visited.Add(current.GetHashCode(), current);
|
|
|
|
|
# List<Cell> neighbours = GetNeighbours(current);
|
|
|
|
|
# foreach (Cell neighbour in neighbours)
|
|
|
|
|
# {
|
|
|
|
|
# if (!visited.ContainsKey(neighbour.GetHashCode()) && !toVisit.Contains(neighbour))
|
|
|
|
|
# {
|
|
|
|
|
# neighbour.DistanceLeft = (target.Position - neighbour.Position).magnitude;
|
|
|
|
|
# toVisit.Push(neighbour);
|
|
|
|
|
# visualise(neighbour, VisualAction.ToVisit);
|
|
|
|
|
# }
|
|
|
|
|
# }
|
|
|
|
|
|
|
|
|
|
# visualise(current, VisualAction.Visited);
|
|
|
|
|
# }
|
|
|
|
|
# return null;
|
|
|
|
|
# }
|