2026-rff_mp/stepushovgs/labyrinth/test.ipynb

176 lines
3.4 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "4489fc7e",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"S # ###\n",
"## # # E\n",
"# # #\n",
"### ## #\n",
"# #\n",
"########\n"
]
}
],
"source": [
"with open('test_lab.txt') as f:\n",
" data = f.readlines()\n",
" for el in data:\n",
" print(el.rstrip())"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "fde1eddb",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"S # ###\n",
"## # # E\n",
"# # #\n",
"### ## #\n",
"# #\n",
"########\n"
]
}
],
"source": [
"from source.classes.builder import TextFileMazeBuilder\n",
"\n",
"builder = TextFileMazeBuilder()\n",
"maze = builder.buildFromFile(filename='test_lab.txt')\n",
"\n",
"maze.printer()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "22325f68",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Загружен лабиринт:\n",
"\u001b[H\u001b[2J**P# ###\n",
"## # # E\n",
"# # #\n",
"### ## #\n",
"# #\n",
"########\n"
]
}
],
"source": [
"from source.bububu.observer import ConsoleView, Event\n",
"\n",
"view = ConsoleView()\n",
"view.update(Event(\n",
" event=\"maze_loaded\",\n",
" maze=maze,\n",
" player_position=(2, 0),\n",
" path=[(0, 0), (1, 0)]\n",
"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "19840429",
"metadata": {},
"outputs": [],
"source": [
"from source.strategy.DFS import DFS\n",
"from source.strategy.maze_solver import MazeSolver\n",
"\n",
"strat = MazeSolver(maze, DFS())\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "857c5c04",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0\n",
"2\n",
"1\n",
"3\n",
"4\n"
]
},
{
"data": {
"text/plain": [
"{'0', '1', '2', '3', '4'}"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def dfs(graph, start, visited=None):\n",
" if visited is None:\n",
" visited = set()\n",
" visited.add(start)\n",
"\n",
" print(start)\n",
"\n",
" for next in graph[start] - visited:\n",
" dfs(graph, next, visited)\n",
" return visited\n",
"\n",
"\n",
"graph = {'0': set(['1', '2']),\n",
" '1': set(['0', '3', '4']),\n",
" '2': set(['0']),\n",
" '3': set(['1']),\n",
" '4': set(['2', '3'])}\n",
"\n",
"dfs(graph, '0')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.14.4"
}
},
"nbformat": 4,
"nbformat_minor": 5
}