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

26 lines
832 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
# Создание новой ячейки
def getCell(self, x, y):
if 0 <= y < self.height and 0 <= x < self.width:
return self.grid[x][y]
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
neighbor = self.getСell(nx, ny)
if neighbor and neighbor.isPassable():
result.append(neighbor)
return result