forked from UNN/2026-rff_mp
add interface MazeBuilder and TextFileMazeBuilder
This commit is contained in:
parent
fc40a296f9
commit
a3e40fe0d5
File diff suppressed because one or more lines are too long
0
pomelovsd/ExitMaze/Builder/Builder.py
Normal file
0
pomelovsd/ExitMaze/Builder/Builder.py
Normal file
12
pomelovsd/ExitMaze/Core/Cell.py
Normal file
12
pomelovsd/ExitMaze/Core/Cell.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
class Cell:
|
||||
def __init__(self, x, y, isWall = False, isStart = False, isExit = False):
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.isWall = isWall
|
||||
self.isStart = isStart
|
||||
self.isExit = isExit
|
||||
|
||||
# Возращает True, если посаседству стена
|
||||
def isPassable(self):
|
||||
return not self.isWall
|
||||
|
||||
26
pomelovsd/ExitMaze/Core/Maze.py
Normal file
26
pomelovsd/ExitMaze/Core/Maze.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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
|
||||
Loading…
Reference in New Issue
Block a user