diff --git a/stepushovgs/labyrinth/source/strategy/__init__.py b/stepushovgs/labyrinth/source/strategy/__init__.py index 5c1d610..2f99492 100644 --- a/stepushovgs/labyrinth/source/strategy/__init__.py +++ b/stepushovgs/labyrinth/source/strategy/__init__.py @@ -1,8 +1,12 @@ +from .strategy import PathFindingStrategy, reconstruct_path +from .maze_solver import MazeSolver + + from .bfs import BFS from .dfs import DFS from .astar import AStar from .dijkstra import Dijkstra -from .maze_solver import MazeSolver -from .strategy import PathFindingStrategy, reconstruct_path +# from .maze_solver import MazeSolver +# from .strategy import PathFindingStrategy, reconstruct_path __all__ = ['BFS', 'DFS', 'AStar', 'Dijkstra', 'MazeSolver', 'PathFindingStrategy', 'reconstruct_path'] \ No newline at end of file diff --git a/stepushovgs/labyrinth/source/strategy/maze_solver.py b/stepushovgs/labyrinth/source/strategy/maze_solver.py index 694612d..269a24f 100644 --- a/stepushovgs/labyrinth/source/strategy/maze_solver.py +++ b/stepushovgs/labyrinth/source/strategy/maze_solver.py @@ -1,7 +1,7 @@ import time -from source.strategy import PathFindingStrategy +from .strategy import PathFindingStrategy from source.observer import Observer, Event from source.classes import Cell, Maze diff --git a/stepushovgs/labyrinth/test.ipynb b/stepushovgs/labyrinth/test.ipynb index 92d9373..d157746 100644 --- a/stepushovgs/labyrinth/test.ipynb +++ b/stepushovgs/labyrinth/test.ipynb @@ -3,6 +3,21 @@ { "cell_type": "code", "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", "metadata": {}, "outputs": [ @@ -28,7 +43,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "fde1eddb", "metadata": {}, "outputs": [ @@ -46,7 +61,7 @@ } ], "source": [ - "from source.builder import TextFileMazeBuilder\n", + "\n", "\n", "builder = TextFileMazeBuilder()\n", "maze = builder.buildFromFile(filename='test_lab.txt')\n", @@ -56,7 +71,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "id": "22325f68", "metadata": {}, "outputs": [ @@ -75,8 +90,8 @@ } ], "source": [ - "from source.observer.console_view import ConsoleView\n", - "from source.observer.observer import Event\n", + "\n", + "# from source.observer.observer import \n", "\n", "view = ConsoleView()\n", "view.update(Event(\n", @@ -89,7 +104,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "19840429", "metadata": {}, "outputs": [ @@ -127,15 +142,13 @@ " (7, 1)])" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "from source.strategy import DFS, MazeSolver\n", - "# from source.strategy.maze_solver import \n", - "from source.classes import Cell\n", + "\n", "\n", "\n", "solver = MazeSolver(maze, DFS(), ConsoleView())\n", @@ -146,26 +159,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "73ba37a8", "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "'module' object is not callable", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "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", - "\u001b[1;31mTypeError\u001b[0m: 'module' object is not callable" + "name": "stdout", + "output_type": "stream", + "text": [ + "Путь найден:\n", + "S**# ###\n", + "##*# #*E\n", + "# ** #*#\n", + "###*##*#\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": [ - "from source.strategy import BFS, MazeSolver\n", - "# from source.strategy import \n", - "from source.classes import Cell\n", + "\n", "\n", "\n", "solver = MazeSolver(maze, BFS(), ConsoleView())\n", @@ -176,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "id": "857c5c04", "metadata": {}, "outputs": [ @@ -187,9 +225,8 @@ "0\n", "2\n", "1\n", - "4\n", "3\n", - "3\n" + "4\n" ] }, { @@ -198,7 +235,7 @@ "{'0', '1', '2', '3', '4'}" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -227,7 +264,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "id": "9a5ea5cb", "metadata": {}, "outputs": [ @@ -313,7 +350,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "id": "32edf4d1", "metadata": {}, "outputs": [