2026-rff_mp/vinichukan/src/model/maze.py
2026-05-24 11:40:51 +03:00

24 lines
647 B
Python

class Maze:
def __init__(self, width, height, cells, start, exit_):
self.width = width
self.height = height
self.cells = cells
self.start = start
self.exit = exit_
def get_cell(self, x, y):
return self.cells[y][x]
def get_neighbors(self, cell):
dirs = [(1,0), (-1,0), (0,1), (0,-1)]
result = []
for dx, dy in dirs:
nx, ny = cell.x + dx, cell.y + dy
if 0 <= nx < self.width and 0 <= ny < self.height:
n = self.get_cell(nx, ny)
if not n.is_wall:
result.append(n)
return result