2026-rff_mp/kuznetsovTD/tusk 2/solver/maze_solver.py
2026-05-25 13:06:15 +03:00

31 lines
987 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import time
from observer.subject import Subject
from observer.maze_event import MazeEvent, MazeEventType
from models.search_stats import SearchStats
class MazeSolver(Subject):
def __init__(self, maze, strategy):
super().__init__()
self.maze = maze
self.strategy = strategy
def set_strategy(self, strategy):
self.strategy = strategy
def solve(self, maze_name="maze"):
start_time = time.perf_counter()
path, visited = self.strategy.find_path(
self.maze, self.maze.start_cell, self.maze.exit_cell
)
end_time = time.perf_counter()
self.notify(MazeEvent(MazeEventType.PATH_FOUND, path))
return SearchStats(
strategy=self.strategy.__class__.__name__,
maze_name=maze_name,
duration=(end_time - start_time) * 1000,
visited_cells=visited,
path_length=len(path) if path else 0 # ЭТУ СТРОКУ ИЗМЕНИТЬ
)