forked from UNN/2026-rff_mp
feat: add MazeSolver orchestrator with SearchStats
This commit is contained in:
parent
931e6a9ccf
commit
e6e4ae9a99
35
lomakinae/docs/data/02/src/solver.py
Normal file
35
lomakinae/docs/data/02/src/solver.py
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import time
|
||||
from typing import NamedTuple
|
||||
|
||||
from .maze import Maze
|
||||
from .strategies import PathFindingStrategy
|
||||
|
||||
|
||||
class SearchStats(NamedTuple):
|
||||
time_ms: float
|
||||
visited_cells: int
|
||||
path_length: int
|
||||
|
||||
|
||||
class MazeSolver:
|
||||
def __init__(self, maze: Maze):
|
||||
self.maze = maze
|
||||
self.strategy = None
|
||||
|
||||
def set_strategy(self, strategy: PathFindingStrategy):
|
||||
self.strategy = strategy
|
||||
|
||||
def solve(self) -> SearchStats:
|
||||
if self.strategy is None:
|
||||
raise ValueError("Strategy not set")
|
||||
|
||||
start_time = time.perf_counter()
|
||||
path = 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=self.strategy.visited_count,
|
||||
path_length=len(path),
|
||||
)
|
||||
Loading…
Reference in New Issue
Block a user