Оркестратор MazeSolver и статистика

This commit is contained in:
tseremonnikovaaa 2026-05-24 20:10:49 +03:00
parent 4c14b6d0b3
commit 9f5a0055f3

View File

@ -179,4 +179,34 @@ class AStarStrategy(PathFindingStrategy):
f = tentative_g + self.heuristic(nb, exit)
heapq.heappush(open_set, (f, counter, nb))
counter += 1
return [], len(visited)
return [], len(visited)
@dataclass
class SearchStats:
time_ms: float
visited_cells: int
path_length: int
algorithm: str
class MazeSolver:
def __init__(self, maze, strategy):
self.maze = maze
self.strategy = strategy
def set_strategy(self, strategy):
self.strategy = strategy
def solve(self):
if self.maze.start is None or self.maze.exit is None:
raise ValueError("Лабиринт не имеет старта или выхода")
start_time = time.perf_counter()
path, visited = self.strategy.find_path(self.maze, self.maze.start, self.maze.exit)
end_time = time.perf_counter()
stats = SearchStats(
time_ms=(end_time - start_time) * 1000,
visited_cells=visited,
path_length=len(path),
algorithm=self.strategy.__class__.__name__
)
return path, stats