2026-rff_mp/stepushovgs/labyrinth/source/classes/maze.py
2026-05-20 13:05:52 +03:00

39 lines
1.1 KiB
Python

from source.classes.cell import Cell
class Maze:
def __init__(self, cells, width, height, start, exit):
self.cells = cells
self.width = width
self.height = height
self.start = start
self.exit = exit
pass
def getCell(self, x, y) -> Cell:
return self.cells[x][y]
def getNeighbors(self, cell) -> list[Cell]:
neighbors = []
c_x, c_y = cell.getXY()
if c_x - 1 >= 0 and not self.cells[c_x - 1][c_y].isWall:
neighbors.append(self.cells[c_x - 1][c_y])
if c_x + 1 < self.width and not self.cells[c_x + 1][c_y].isWall:
neighbors.append(self.cells[c_x + 1][c_y])
if c_y - 1 >= 0 and not self.cells[c_x][c_y - 1].isWall:
neighbors.append(self.cells[c_x][c_y - 1])
if c_y + 1 < self.height and not self.cells[c_x][c_y + 1].isWall:
neighbors.append(self.cells[c_x][c_y + 1])
return neighbors
def printer(self):
for line in self.cells:
for c in line:
print(c.toStr(), end='')
print()