From 47404cfa9db552cbe77edb96620323d59bba6480 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=20=D0=9C=D0=B0?= =?UTF-8?q?=D1=82=D0=B2=D0=B5=D0=B9?= Date: Tue, 19 May 2026 21:46:18 +0300 Subject: [PATCH] =?UTF-8?q?[2]=20=D0=9A=D0=BB=D0=B0=D1=81=D1=81=D1=8B=20ce?= =?UTF-8?q?ll=20=D0=B8=20maze=20+=20=D0=BC=D0=B0=D0=BB.=20=D0=BB=D0=B0?= =?UTF-8?q?=D0=B1=D0=B8=D1=80=D0=B8=D0=BD=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BorisovMI/lab_2/docs/data/maze.py | 68 ++++++++++++++++++++++++ BorisovMI/lab_2/docs/data/maze_small.txt | 10 ++++ 2 files changed, 78 insertions(+) create mode 100644 BorisovMI/lab_2/docs/data/maze.py create mode 100644 BorisovMI/lab_2/docs/data/maze_small.txt diff --git a/BorisovMI/lab_2/docs/data/maze.py b/BorisovMI/lab_2/docs/data/maze.py new file mode 100644 index 0000000..aabd9ad --- /dev/null +++ b/BorisovMI/lab_2/docs/data/maze.py @@ -0,0 +1,68 @@ +from abc import ABC, abstractclassmethod +from collections import deque +import heapq +import time +import os +import time +import csv +import random +class Cell: + def __init__(self, x, y): + self.x = x + self.y = y + self.isWall = False + self.isStart = False + self.isExit = False + + + def __eq__(self, other): + if other is None: + return False + return self.x == other.x and self.y == other.y + def __lt__(self, other): + + if other is None: + return False + return (self.x, self.y) < (other.x, other.y) + def __hash__(self): + + return hash((self.x, self.y)) + + def __repr__(self): + return f"Cell({self.x}, {self.y})" + def isPassable(self): + return not self.isWall + +class Maze: + def __init__(self, width, height): + self.width = width + self.height = height + self.grid = [[Cell(x, y) for y in range(height)] for x in range(width)] + self.start = None + self.exit = None + + def getCell(self, x, y): + if 0 <= x < self.width and 0 <= y < self.height: + return self.grid[x][y] + return None + + def getNeighbors(self, cell): + neighbors = [] + directions = [(0, 1), (0, -1), (1, 0), (-1, 0)] + for dx, dy in directions: + neighbor = self.getCell(cell.x + dx, cell.y + dy) + if neighbor and neighbor.isPassable(): + neighbors.append(neighbor) + return neighbors + + def setStart(self, x, y): + cell = self.getCell(x, y) + if cell: + cell.isStart = True + self.start = cell + + def setExit(self, x, y): + cell = self.getCell(x, y) + if cell: + cell.isExit = True + self.exit = cell \ No newline at end of file diff --git a/BorisovMI/lab_2/docs/data/maze_small.txt b/BorisovMI/lab_2/docs/data/maze_small.txt new file mode 100644 index 0000000..49f58c6 --- /dev/null +++ b/BorisovMI/lab_2/docs/data/maze_small.txt @@ -0,0 +1,10 @@ +s + + # # # + # ## + # ## +## ## + # ## + # + # + e