diff --git a/MininaVD/docs2/data2/strategiesPathfinding_strategy.ipynb b/MininaVD/docs2/data2/strategiesPathfinding_strategy.ipynb new file mode 100644 index 0000000..6c641ac --- /dev/null +++ b/MininaVD/docs2/data2/strategiesPathfinding_strategy.ipynb @@ -0,0 +1,67 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "3f8f5923-00bf-4fc2-88e9-6a51d6183c5b", + "metadata": {}, + "outputs": [], + "source": [ + "from abc import ABC, abstractmethod\n", + "from typing import List, Optional\n", + "from modelsMaze import Maze\n", + "from modelsCell import Cell\n", + "\n", + "class PathFindingStrategy(ABC):\n", + " \"\"\"Интерфейс стратегии поиска пути (паттерн Strategy).\"\"\"\n", + " \n", + " @abstractmethod\n", + " def find_path(self, maze: Maze, start: Cell, exit_cell: Cell) -> List[Cell]:\n", + " \"\"\"\n", + " Найти путь от start до exit_cell.\n", + " Возвращает список клеток пути (включая start и exit) или пустой список.\n", + " \"\"\"\n", + " pass\n", + " \n", + " @property\n", + " @abstractmethod\n", + " def name(self) -> str:\n", + " \"\"\"Имя стратегии для отчётов.\"\"\"\n", + " pass\n", + " \n", + " def _reconstruct_path(self, came_from: dict, start: Cell, current: Cell) -> List[Cell]:\n", + " \"\"\"Восстановить путь из словаря предков.\"\"\"\n", + " path = []\n", + " while current != start:\n", + " path.append(current)\n", + " current = came_from.get(current)\n", + " if current is None:\n", + " return []\n", + " path.append(start)\n", + " path.reverse()\n", + " return path" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.9" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}