2026-rff_mp/pomelovsd/ExitMaze/Core/Maze.py

22 lines
705 B
Python
Raw Normal View History

2026-05-25 13:02:23 +00:00
class Maze:
def __init__(self, grid, start=None, exit=None):
self.grid = grid
self.start = start
self.exit = exit
self.height = len(grid)
self.width = len(grid[0]) if grid else 0
2026-05-25 13:02:23 +00:00
def getCell(self, x, y):
if 0 <= x < self.width and 0 <= y < self.height:
return self.grid[y][x]
return None
def getNeighbors(self, cell):
directions = [(0,1),(1,0),(0,-1),(-1,0)]
result = []
for dx, dy in directions:
nx, ny = cell.x + dx, cell.y + dy
2026-05-25 10:45:18 +00:00
neighbor = self.getCell(nx, ny)
if neighbor and neighbor.isPassable():
result.append(neighbor)
2026-05-25 13:02:23 +00:00
return result