forked from UNN/2026-rff_mp
35 lines
981 B
Python
35 lines
981 B
Python
|
|
import time
|
|||
|
|
|
|||
|
|
|
|||
|
|
from source.strategy.strategy import SearchStats, PathFindingStrategy
|
|||
|
|
|
|||
|
|
class MazeSolver:
|
|||
|
|
def __init__(self, maze, strategy: PathFindingStrategy):
|
|||
|
|
self.maze = maze
|
|||
|
|
self.strategy = strategy
|
|||
|
|
|
|||
|
|
def strategyName(self):
|
|||
|
|
return self.strategy.name
|
|||
|
|
|
|||
|
|
def setStrategy(self, strategy: PathFindingStrategy):
|
|||
|
|
self.strategy = strategy
|
|||
|
|
|
|||
|
|
def solve(self):
|
|||
|
|
start_time = time.perf_counter()
|
|||
|
|
path, visited_cells = self.strategy.findPath(self.maze)
|
|||
|
|
finish_time = time.perf_counter()
|
|||
|
|
|
|||
|
|
return SearchStats(
|
|||
|
|
timeMs=finish_time - start_time,
|
|||
|
|
visitedCells=visited_cells,
|
|||
|
|
pathLength=len(path)
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
class SearchStats:
|
|||
|
|
"""Общая информация о тесте алгоритма"""
|
|||
|
|
def __init__(self, timeMs: float, visitedCells: int, pathLength: int):
|
|||
|
|
self.timeMs = timeMs
|
|||
|
|
self.visitedCells = visitedCells
|
|||
|
|
self.pathLength = pathLength
|