Реализован этап 1
This commit is contained in:
parent
94a9cba182
commit
b002e85958
0
MusinAA/task2/__init__.py
Normal file
0
MusinAA/task2/__init__.py
Normal file
0
MusinAA/task2/mazeObjects/__init__.py
Normal file
0
MusinAA/task2/mazeObjects/__init__.py
Normal file
13
MusinAA/task2/mazeObjects/cell.py
Normal file
13
MusinAA/task2/mazeObjects/cell.py
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
class Cell:
|
||||||
|
"""Хранит координаты (x, y)
|
||||||
|
флаги isWall, isStart, isExit
|
||||||
|
метод isPassable() (возвращает True для прохода, если не стена)."""
|
||||||
|
def __init__(self, x: int, y: int, isWall = False, isStart = False, isExit = False):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
self.isWall = isWall
|
||||||
|
self.isStart = isStart
|
||||||
|
self.isExit = isExit
|
||||||
|
|
||||||
|
def isPassable(self):
|
||||||
|
return not self.isWall
|
||||||
40
MusinAA/task2/mazeObjects/maze.py
Normal file
40
MusinAA/task2/mazeObjects/maze.py
Normal file
|
|
@ -0,0 +1,40 @@
|
||||||
|
from task2.mazeObjects.cell import Cell
|
||||||
|
|
||||||
|
class Maze:
|
||||||
|
"""Хранит двумерный массив клеток,
|
||||||
|
ширину, высоту, ссылки на стартовую и выходную клетку.
|
||||||
|
Методы:
|
||||||
|
getCell(x, y), getNeighbors(cell) – возвращает список соседних проходимых клеток
|
||||||
|
(вверх, вниз, влево, вправо, если в пределах границ и не стена)."""
|
||||||
|
|
||||||
|
def __init__(self, mazeArray: list[list[Cell]], start: dict, end: dict) -> None:
|
||||||
|
self.mazeArray = mazeArray
|
||||||
|
self.width = len(mazeArray)
|
||||||
|
self.height = len(mazeArray[0])
|
||||||
|
|
||||||
|
self.startCell = self.getCell(start['x'], start['y'])
|
||||||
|
self.endCell = self.getCell(end['x'], end['y'])
|
||||||
|
|
||||||
|
def getCell(self, x: int, y: int):
|
||||||
|
return self.mazeArray[y][x]
|
||||||
|
|
||||||
|
def checkCell(self, x: int, y: int):
|
||||||
|
if not(0 <= x and x < self.width):
|
||||||
|
return False
|
||||||
|
if not(0 <= y and y < self.height):
|
||||||
|
return False
|
||||||
|
return self.getCell(x, y).isPassable()
|
||||||
|
|
||||||
|
def getNeighbors(self, cell: Cell):
|
||||||
|
point = (cell.x, cell.y)
|
||||||
|
offsets = ((0, 1),
|
||||||
|
(0, -1),
|
||||||
|
(-1, 0),
|
||||||
|
(1, 0))
|
||||||
|
passableCells = []
|
||||||
|
for ofst in offsets:
|
||||||
|
x = point[0]+ofst[0]
|
||||||
|
y = point[1]+ofst[1]
|
||||||
|
if self.checkCell(x, y):
|
||||||
|
passableCells.append(self.getCell(x, y))
|
||||||
|
return passableCells
|
||||||
Loading…
Reference in New Issue
Block a user