From 055a73325b9b0abc64c8c9c7c0af513467855f32 Mon Sep 17 00:00:00 2001 From: Veronika Minina Date: Sun, 17 May 2026 14:23:43 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3?= =?UTF-8?q?=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../strategiesPathfinding_strategy.ipynb | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 MininaVD/docs2/data2/strategiesPathfinding_strategy.ipynb 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 +}