forked from UNN/2026-rff_mp
28 lines
915 B
Python
28 lines
915 B
Python
import time
|
|
from dataclasses import dataclass, field
|
|
from typing import List
|
|
from maze import Maze, Cell
|
|
from strategies import PathFindingStrategy
|
|
|
|
@dataclass
|
|
class SearchStats:
|
|
time_ms: float
|
|
visited_cells: int
|
|
path_length: int
|
|
path: List[Cell] = field(default_factory=list)
|
|
|
|
class MazeSolver:
|
|
def __init__(self, maze: Maze, strategy: PathFindingStrategy):
|
|
self.maze = maze
|
|
self.strategy = strategy
|
|
|
|
def set_strategy(self, strategy: PathFindingStrategy):
|
|
self.strategy = strategy
|
|
|
|
def solve(self) -> SearchStats:
|
|
start_time = time.perf_counter()
|
|
path, visited = self.strategy.find_path(self.maze, self.maze.start, self.maze.exit)
|
|
end_time = time.perf_counter()
|
|
time_ms = (end_time - start_time) * 1000
|
|
return SearchStats(time_ms=time_ms, visited_cells=visited,
|
|
path_length=len(path), path=path) |