mirror of
https://github.com/maoakeEnterprise/amazing.git
synced 2026-04-28 16:04:35 +02:00
add generator to my maze generator DFS
This commit is contained in:
+5
-14
@@ -1,30 +1,21 @@
|
||||
import os
|
||||
from src.amaz_lib import Kruskal
|
||||
from src.amaz_lib import DepthFirstSearch
|
||||
from src.amaz_lib import Maze
|
||||
from src.amaz_lib import MazeGenerator
|
||||
import src.amaz_lib as g
|
||||
|
||||
|
||||
def main() -> None:
|
||||
def main(maze_gen: MazeGenerator) -> None:
|
||||
# try:
|
||||
maze = Maze(maze=None)
|
||||
gen = Kruskal().generator(10, 10)
|
||||
gen = maze_gen.generator(100, 100)
|
||||
for alg in gen:
|
||||
maze.set_maze(alg)
|
||||
os.system("clear")
|
||||
maze.ascii_print()
|
||||
|
||||
|
||||
def main2() -> None:
|
||||
maze = Maze(maze=None)
|
||||
gen = DepthFirstSearch.generator(50, 50)
|
||||
maze.set_maze(gen)
|
||||
os.system("clear")
|
||||
maze.ascii_print()
|
||||
|
||||
|
||||
# except Exception as err:
|
||||
# print(err)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main2()
|
||||
main(g.DepthFirstSearch())
|
||||
|
||||
@@ -84,10 +84,10 @@ class Kruskal(MazeGenerator):
|
||||
return self.walls_to_maze(walls, height, width)
|
||||
|
||||
|
||||
class DepthFirstSearch:
|
||||
class DepthFirstSearch(MazeGenerator):
|
||||
|
||||
@staticmethod
|
||||
def generator(width: int, height: int) -> np.ndarray:
|
||||
def generator(self, width: int, height: int
|
||||
) -> Generator[np.ndarray, None, np.ndarray]:
|
||||
maze = DepthFirstSearch.init_maze(width, height)
|
||||
visited = np.zeros((height, width), dtype=bool)
|
||||
path = list()
|
||||
@@ -117,6 +117,7 @@ class DepthFirstSearch:
|
||||
wall_r = DepthFirstSearch.reverse_path(wall)
|
||||
x, y = coord
|
||||
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall_r)
|
||||
yield maze
|
||||
return maze
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user