diff --git a/stepushovgs/labyrinth/source/strategy/maze_solver.py b/stepushovgs/labyrinth/source/strategy/maze_solver.py index c32173f..805246e 100644 --- a/stepushovgs/labyrinth/source/strategy/maze_solver.py +++ b/stepushovgs/labyrinth/source/strategy/maze_solver.py @@ -2,11 +2,14 @@ import time from source.strategy.strategy import SearchStats, PathFindingStrategy +from source.bububu.observer import Observer, Event +from source.classes.maze import Maze class MazeSolver: - def __init__(self, maze, strategy: PathFindingStrategy): + def __init__(self, maze: Maze, strategy: PathFindingStrategy, observer: Observer): self.maze = maze self.strategy = strategy + self.observer = observer def strategyName(self): return self.strategy.name @@ -19,6 +22,12 @@ class MazeSolver: path, visited_cells = self.strategy.findPath(self.maze) finish_time = time.perf_counter() + self.observer.update(Event( + event="path_found", + player_position=self.maze.exit, + path=path + )) + return SearchStats( timeMs=finish_time - start_time, visitedCells=visited_cells, diff --git a/stepushovgs/labyrinth/source/strategy/strategy.py b/stepushovgs/labyrinth/source/strategy/strategy.py index b55fc2e..5449a22 100644 --- a/stepushovgs/labyrinth/source/strategy/strategy.py +++ b/stepushovgs/labyrinth/source/strategy/strategy.py @@ -9,8 +9,8 @@ class PathFindingStrategy(ABC): """Интерфейс для семейства алгоритмов поиска пути от старта до выхода.""" @abstractmethod - def findPath(self, maze: Maze) -> tuple[list[Cell], int]: - """Возвращающим список клеток пути (от старта до выхода включительно) или пустой список, если пути нет и количество посещённых клеток.""" + def findPath(self, maze: Maze) -> tuple[list[tuple[int, int]], int]: + """Возвращающим список координат клеток пути (от старта до выхода включительно) или пустой список, если пути нет и количество посещённых клеток.""" pass @property @abstractmethod