From 8f4cf0908383c0132b72718dfbac623fe3d7c03b Mon Sep 17 00:00:00 2001 From: GordStep Date: Wed, 20 May 2026 23:16:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB=20ma?= =?UTF-8?q?zesolver=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BE=D0=BD?= =?UTF-8?q?=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=D0=B8=D1=82=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B9=D0=B4=D0=B5=D0=BD=D1=8B=D0=B9=20=D0=BC=D0=B0=D1=80=D1=88?= =?UTF-8?q?=D1=80=D1=83=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stepushovgs/labyrinth/source/strategy/maze_solver.py | 11 ++++++++++- stepushovgs/labyrinth/source/strategy/strategy.py | 4 ++-- 2 files changed, 12 insertions(+), 3 deletions(-) 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