forked from UNN/2026-rff_mp
46 lines
1.7 KiB
Python
46 lines
1.7 KiB
Python
from .cell import Cell
|
||
|
||
class Maze:
|
||
"""Лабиринт"""
|
||
def __init__(self, cells, width: int, height: int, start: Cell, exit_cell: Cell):
|
||
self.cells = cells
|
||
self.width = width
|
||
self.height = height
|
||
self.start = start
|
||
self.exit = exit_cell
|
||
pass
|
||
|
||
def getCell(self, x: int, y: int) -> Cell:
|
||
return self.cells[y][x] # строка стобец
|
||
|
||
def getNeighbors(self, cell) -> list[Cell]:
|
||
"""Возвращает список соседних проходимых клеток (вверх, вниз, влево, вправо, если в пределах границ и не стена)."""
|
||
neighbors = []
|
||
|
||
c_x, c_y = cell.getXY()
|
||
|
||
if c_y - 1 >= 0 and not self.cells[c_y - 1][c_x].isWall:
|
||
neighbors.append(self.cells[c_y - 1][c_x])
|
||
|
||
if c_y + 1 < self.height and not self.cells[c_y + 1][c_x].isWall:
|
||
neighbors.append(self.cells[c_y + 1][c_x])
|
||
|
||
if c_x - 1 >= 0 and not self.cells[c_y][c_x - 1].isWall:
|
||
neighbors.append(self.cells[c_y][c_x - 1])
|
||
|
||
if c_x + 1 < self.width and not self.cells[c_y][c_x + 1].isWall:
|
||
neighbors.append(self.cells[c_y][c_x + 1])
|
||
|
||
return neighbors
|
||
|
||
def printer(self):
|
||
"""Выводит в консоль лабиринт (отладочное)"""
|
||
for line in self.cells:
|
||
for c in line:
|
||
print(c.toStr(), end='')
|
||
|
||
print()
|
||
|
||
def info(self):
|
||
"""Основная информация о лабиринте"""
|
||
print(f'height: {self.height}\nwidth: {self.width}\nstart: {self.start.getXY()}\nexit: {self.exit.getXY()}\ncount cells: {self.height * self.width}') |