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