Изсправил ошибки циклического импорта

This commit is contained in:
GordStep 2026-05-22 00:17:01 +03:00
parent 06f8192f6a
commit d8fb7ab226
3 changed files with 72 additions and 31 deletions

View File

@ -1,8 +1,12 @@
from .strategy import PathFindingStrategy, reconstruct_path
from .maze_solver import MazeSolver
from .bfs import BFS from .bfs import BFS
from .dfs import DFS from .dfs import DFS
from .astar import AStar from .astar import AStar
from .dijkstra import Dijkstra from .dijkstra import Dijkstra
from .maze_solver import MazeSolver # from .maze_solver import MazeSolver
from .strategy import PathFindingStrategy, reconstruct_path # from .strategy import PathFindingStrategy, reconstruct_path
__all__ = ['BFS', 'DFS', 'AStar', 'Dijkstra', 'MazeSolver', 'PathFindingStrategy', 'reconstruct_path'] __all__ = ['BFS', 'DFS', 'AStar', 'Dijkstra', 'MazeSolver', 'PathFindingStrategy', 'reconstruct_path']

View File

@ -1,7 +1,7 @@
import time import time
from source.strategy import PathFindingStrategy from .strategy import PathFindingStrategy
from source.observer import Observer, Event from source.observer import Observer, Event
from source.classes import Cell, Maze from source.classes import Cell, Maze

View File

@ -3,6 +3,21 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 1, "execution_count": 1,
"id": "4dbe48b6",
"metadata": {},
"outputs": [],
"source": [
"from source.builder import TextFileMazeBuilder\n",
"from source.observer import ConsoleView, Event\n",
"from source.strategy import MazeSolver, BFS, DFS\n",
"# from source.strategy.maze_solver import \n",
"from source.classes import Cell\n",
"# from source.strategy import "
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "4489fc7e", "id": "4489fc7e",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -28,7 +43,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 3,
"id": "fde1eddb", "id": "fde1eddb",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -46,7 +61,7 @@
} }
], ],
"source": [ "source": [
"from source.builder import TextFileMazeBuilder\n", "\n",
"\n", "\n",
"builder = TextFileMazeBuilder()\n", "builder = TextFileMazeBuilder()\n",
"maze = builder.buildFromFile(filename='test_lab.txt')\n", "maze = builder.buildFromFile(filename='test_lab.txt')\n",
@ -56,7 +71,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 3, "execution_count": 4,
"id": "22325f68", "id": "22325f68",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -75,8 +90,8 @@
} }
], ],
"source": [ "source": [
"from source.observer.console_view import ConsoleView\n", "\n",
"from source.observer.observer import Event\n", "# from source.observer.observer import \n",
"\n", "\n",
"view = ConsoleView()\n", "view = ConsoleView()\n",
"view.update(Event(\n", "view.update(Event(\n",
@ -89,7 +104,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 5,
"id": "19840429", "id": "19840429",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -127,15 +142,13 @@
" (7, 1)])" " (7, 1)])"
] ]
}, },
"execution_count": 4, "execution_count": 5,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
], ],
"source": [ "source": [
"from source.strategy import DFS, MazeSolver\n", "\n",
"# from source.strategy.maze_solver import \n",
"from source.classes import Cell\n",
"\n", "\n",
"\n", "\n",
"solver = MazeSolver(maze, DFS(), ConsoleView())\n", "solver = MazeSolver(maze, DFS(), ConsoleView())\n",
@ -146,26 +159,51 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 6,
"id": "73ba37a8", "id": "73ba37a8",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
{ {
"ename": "TypeError", "name": "stdout",
"evalue": "'module' object is not callable", "output_type": "stream",
"output_type": "error", "text": [
"traceback": [ "Путь найден:\n",
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "S**# ###\n",
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", "##*# #*E\n",
"Cell \u001b[1;32mIn[9], line 6\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01msource\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mstrategy\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmaze_solver\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m MazeSolver\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;21;01msource\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mclasses\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mcell\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mimport\u001b[39;00m Cell\n\u001b[1;32m----> 6\u001b[0m solver \u001b[38;5;241m=\u001b[39m MazeSolver(maze, \u001b[43mBFS\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m, ConsoleView())\n\u001b[0;32m 7\u001b[0m stats \u001b[38;5;241m=\u001b[39m solver\u001b[38;5;241m.\u001b[39msolve()\n\u001b[0;32m 9\u001b[0m [cord\u001b[38;5;241m.\u001b[39mgetXY() \u001b[38;5;28;01mfor\u001b[39;00m cord \u001b[38;5;129;01min\u001b[39;00m maze\u001b[38;5;241m.\u001b[39mgetNeighbors(cell\u001b[38;5;241m=\u001b[39mCell(\u001b[38;5;241m2\u001b[39m, \u001b[38;5;241m0\u001b[39m))], [cord\u001b[38;5;241m.\u001b[39mgetXY() \u001b[38;5;28;01mfor\u001b[39;00m cord \u001b[38;5;129;01min\u001b[39;00m stats\u001b[38;5;241m.\u001b[39mpath]\n", "# ** #*#\n",
"\u001b[1;31mTypeError\u001b[0m: 'module' object is not callable" "###*##*#\n",
"# ****#\n",
"########\n"
] ]
},
{
"data": {
"text/plain": [
"([(2, 1), (1, 0)],\n",
" [(0, 0),\n",
" (1, 0),\n",
" (2, 0),\n",
" (2, 1),\n",
" (2, 2),\n",
" (3, 2),\n",
" (3, 3),\n",
" (3, 4),\n",
" (4, 4),\n",
" (5, 4),\n",
" (6, 4),\n",
" (6, 3),\n",
" (6, 2),\n",
" (6, 1),\n",
" (7, 1)])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
} }
], ],
"source": [ "source": [
"from source.strategy import BFS, MazeSolver\n", "\n",
"# from source.strategy import \n",
"from source.classes import Cell\n",
"\n", "\n",
"\n", "\n",
"solver = MazeSolver(maze, BFS(), ConsoleView())\n", "solver = MazeSolver(maze, BFS(), ConsoleView())\n",
@ -176,7 +214,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 6, "execution_count": 7,
"id": "857c5c04", "id": "857c5c04",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -187,9 +225,8 @@
"0\n", "0\n",
"2\n", "2\n",
"1\n", "1\n",
"4\n",
"3\n", "3\n",
"3\n" "4\n"
] ]
}, },
{ {
@ -198,7 +235,7 @@
"{'0', '1', '2', '3', '4'}" "{'0', '1', '2', '3', '4'}"
] ]
}, },
"execution_count": 6, "execution_count": 7,
"metadata": {}, "metadata": {},
"output_type": "execute_result" "output_type": "execute_result"
} }
@ -227,7 +264,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 7, "execution_count": 8,
"id": "9a5ea5cb", "id": "9a5ea5cb",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [
@ -313,7 +350,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 8, "execution_count": 9,
"id": "32edf4d1", "id": "32edf4d1",
"metadata": {}, "metadata": {},
"outputs": [ "outputs": [