forked from UNN/2026-rff_mp
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
#!/usr/bin/env python
|
|
# coding: utf-8
|
|
|
|
# In[ ]:
|
|
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import List, Optional
|
|
from modelsMaze import Maze
|
|
from modelsCell import Cell
|
|
|
|
class PathFindingStrategy(ABC):
|
|
"""Интерфейс стратегии поиска пути (паттерн Strategy)."""
|
|
|
|
@abstractmethod
|
|
def find_path(self, maze: Maze, start: Cell, exit_cell: Cell) -> List[Cell]:
|
|
"""
|
|
Найти путь от start до exit_cell.
|
|
Возвращает список клеток пути (включая start и exit) или пустой список.
|
|
"""
|
|
pass
|
|
|
|
@property
|
|
@abstractmethod
|
|
def name(self) -> str:
|
|
"""Имя стратегии для отчётов."""
|
|
pass
|
|
|
|
def _reconstruct_path(self, came_from: dict, start: Cell, current: Cell) -> List[Cell]:
|
|
"""Восстановить путь из словаря предков."""
|
|
path = []
|
|
while current != start:
|
|
path.append(current)
|
|
current = came_from.get(current)
|
|
if current is None:
|
|
return []
|
|
path.append(start)
|
|
path.reverse()
|
|
return path
|
|
|