mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
starting the branch parsing need to get a good start on this
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ import src.amaz_lib as g
|
|||||||
def main(maze_gen: MazeGenerator) -> None:
|
def main(maze_gen: MazeGenerator) -> None:
|
||||||
# try:
|
# try:
|
||||||
maze = Maze(maze=None)
|
maze = Maze(maze=None)
|
||||||
for alg in maze_gen.generator(30, 10):
|
for alg in maze_gen.generator(30, 30):
|
||||||
maze.set_maze(alg)
|
maze.set_maze(alg)
|
||||||
os.system("clear")
|
os.system("clear")
|
||||||
maze.ascii_print()
|
maze.ascii_print()
|
||||||
|
|||||||
@@ -108,35 +108,38 @@ class DepthFirstSearch(MazeGenerator):
|
|||||||
def generator(
|
def generator(
|
||||||
self, height: int, width: int
|
self, height: int, width: int
|
||||||
) -> Generator[np.ndarray, None, np.ndarray]:
|
) -> Generator[np.ndarray, None, np.ndarray]:
|
||||||
maze = DepthFirstSearch.init_maze(width, height)
|
maze = self.init_maze(width, height)
|
||||||
visited = np.zeros((height, width), dtype=bool)
|
visited = np.zeros((height, width), dtype=bool)
|
||||||
path = list()
|
path = list()
|
||||||
w_h = (width, height)
|
w_h = (width, height)
|
||||||
coord = (0, 0)
|
coord = (0, 0)
|
||||||
x, y = coord
|
x, y = coord
|
||||||
first = True
|
first_iteration = True
|
||||||
|
visited = self.lock_cell_ft(visited, (10, 10))
|
||||||
|
|
||||||
|
while path or first_iteration:
|
||||||
|
first_iteration = False
|
||||||
|
|
||||||
while path or first:
|
|
||||||
first = False
|
|
||||||
visited[y, x] = True
|
visited[y, x] = True
|
||||||
path = DepthFirstSearch.add_cell_visited(coord, path)
|
path = self.add_cell_visited(coord, path)
|
||||||
random_c = DepthFirstSearch.random_cells(visited, coord, w_h)
|
|
||||||
if len(random_c) == 0:
|
random_c = self.random_cells(visited, coord, w_h)
|
||||||
path = DepthFirstSearch.back_on_step(path, w_h, visited)
|
|
||||||
if path:
|
if not random_c:
|
||||||
coord = path[-1]
|
path = self.back_on_step(path, w_h, visited)
|
||||||
random_c = DepthFirstSearch.random_cells(visited, coord, w_h)
|
|
||||||
x, y = coord
|
|
||||||
if not path:
|
if not path:
|
||||||
break
|
break
|
||||||
|
coord = path[-1]
|
||||||
wall = DepthFirstSearch.next_step(random_c)
|
random_c = self.random_cells(visited, coord, w_h)
|
||||||
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall)
|
|
||||||
|
|
||||||
coord = DepthFirstSearch.next_cell(x, y, wall)
|
|
||||||
wall_r = DepthFirstSearch.reverse_path(wall)
|
|
||||||
x, y = coord
|
x, y = coord
|
||||||
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall_r)
|
|
||||||
|
wall = self.next_step(random_c)
|
||||||
|
maze[y][x] = self.broken_wall(maze[y][x], wall)
|
||||||
|
|
||||||
|
coord = self.next_cell(x, y, wall)
|
||||||
|
wall_r = self.reverse_path(wall)
|
||||||
|
x, y = coord
|
||||||
|
maze[y][x] = self.broken_wall(maze[y][x], wall_r)
|
||||||
yield maze
|
yield maze
|
||||||
return maze
|
return maze
|
||||||
|
|
||||||
@@ -194,19 +197,22 @@ class DepthFirstSearch(MazeGenerator):
|
|||||||
return (x + add_x, y + add_y)
|
return (x + add_x, y + add_y)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def reverse_path(next: str) -> str:
|
def reverse_path(direction: str) -> str:
|
||||||
reverse = {"N": "S", "S": "N", "W": "E", "E": "W"}
|
return {"N": "S", "S": "N", "W": "E", "E": "W"}[direction]
|
||||||
return reverse[next]
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def back_on_step(path: list, w_h: tuple, visited: np.array) -> list:
|
def back_on_step(path: list, w_h: tuple, visited: np.array) -> list:
|
||||||
|
while path:
|
||||||
last = path[-1]
|
last = path[-1]
|
||||||
r_cells = DepthFirstSearch.random_cells(visited, last, w_h)
|
if DepthFirstSearch.random_cells(visited, last, w_h):
|
||||||
while len(path) > 0:
|
|
||||||
path.pop()
|
|
||||||
if path:
|
|
||||||
last = path[-1]
|
|
||||||
r_cells = DepthFirstSearch.random_cells(visited, last, w_h)
|
|
||||||
if r_cells:
|
|
||||||
break
|
break
|
||||||
|
path.pop()
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def lock_cell_ft(visited: np.ndarray, coord: tuple) -> np.ndarray:
|
||||||
|
x, y = coord
|
||||||
|
for dy in range(y, y + 7):
|
||||||
|
for dx in range(x, x + 11):
|
||||||
|
visited[dy, dx] = True
|
||||||
|
return visited
|
||||||
|
|||||||
Reference in New Issue
Block a user