From b002e859589720fda848a4e37fcced96f98e83f1 Mon Sep 17 00:00:00 2001 From: oSTEVEo Date: Fri, 24 Apr 2026 06:14:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=20=D1=8D=D1=82=D0=B0=D0=BF=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MusinAA/task2/__init__.py | 0 MusinAA/task2/mazeObjects/__init__.py | 0 MusinAA/task2/mazeObjects/cell.py | 13 +++++++++ MusinAA/task2/mazeObjects/maze.py | 40 +++++++++++++++++++++++++++ 4 files changed, 53 insertions(+) create mode 100644 MusinAA/task2/__init__.py create mode 100644 MusinAA/task2/mazeObjects/__init__.py create mode 100644 MusinAA/task2/mazeObjects/cell.py create mode 100644 MusinAA/task2/mazeObjects/maze.py diff --git a/MusinAA/task2/__init__.py b/MusinAA/task2/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/MusinAA/task2/mazeObjects/__init__.py b/MusinAA/task2/mazeObjects/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/MusinAA/task2/mazeObjects/cell.py b/MusinAA/task2/mazeObjects/cell.py new file mode 100644 index 0000000..2eaf73f --- /dev/null +++ b/MusinAA/task2/mazeObjects/cell.py @@ -0,0 +1,13 @@ +class Cell: + """Хранит координаты (x, y) + флаги isWall, isStart, isExit + метод isPassable() (возвращает True для прохода, если не стена).""" + def __init__(self, x: int, y: int, isWall = False, isStart = False, isExit = False): + self.x = x + self.y = y + self.isWall = isWall + self.isStart = isStart + self.isExit = isExit + + def isPassable(self): + return not self.isWall diff --git a/MusinAA/task2/mazeObjects/maze.py b/MusinAA/task2/mazeObjects/maze.py new file mode 100644 index 0000000..042b8df --- /dev/null +++ b/MusinAA/task2/mazeObjects/maze.py @@ -0,0 +1,40 @@ +from task2.mazeObjects.cell import Cell + +class Maze: + """Хранит двумерный массив клеток, + ширину, высоту, ссылки на стартовую и выходную клетку. + Методы: + getCell(x, y), getNeighbors(cell) – возвращает список соседних проходимых клеток + (вверх, вниз, влево, вправо, если в пределах границ и не стена).""" + + def __init__(self, mazeArray: list[list[Cell]], start: dict, end: dict) -> None: + self.mazeArray = mazeArray + self.width = len(mazeArray) + self.height = len(mazeArray[0]) + + self.startCell = self.getCell(start['x'], start['y']) + self.endCell = self.getCell(end['x'], end['y']) + + def getCell(self, x: int, y: int): + return self.mazeArray[y][x] + + def checkCell(self, x: int, y: int): + if not(0 <= x and x < self.width): + return False + if not(0 <= y and y < self.height): + return False + return self.getCell(x, y).isPassable() + + def getNeighbors(self, cell: Cell): + point = (cell.x, cell.y) + offsets = ((0, 1), + (0, -1), + (-1, 0), + (1, 0)) + passableCells = [] + for ofst in offsets: + x = point[0]+ofst[0] + y = point[1]+ofst[1] + if self.checkCell(x, y): + passableCells.append(self.getCell(x, y)) + return passableCells \ No newline at end of file