32 lines
922 B
Python
32 lines
922 B
Python
from models.cell import Cell
|
|
|
|
|
|
class Maze:
|
|
def __init__(self, cells, start_cell, exit_cell):
|
|
self.cells = cells
|
|
self.height = len(cells)
|
|
self.width = len(cells[0])
|
|
self.start_cell = start_cell
|
|
self.exit_cell = exit_cell
|
|
|
|
def get_cell(self, x, y):
|
|
if 0 <= x < self.width and 0 <= y < self.height:
|
|
return self.cells[y][x]
|
|
return None
|
|
|
|
def check_cell(self, x, y):
|
|
cell = self.get_cell(x, y)
|
|
return cell and cell.is_passable()
|
|
|
|
def get_neighbors(self, cell: Cell):
|
|
directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
|
|
neighbors = []
|
|
for dx, dy in directions:
|
|
x = cell.x + dx
|
|
y = cell.y + dy
|
|
if self.check_cell(x, y):
|
|
neighbors.append(self.get_cell(x, y))
|
|
return neighbors
|
|
|
|
def __repr__(self):
|
|
return f"Maze({self.width}x{self.height})" |