finish the maze generator

This commit is contained in:
Maoake Teriierooiterai
2026-03-24 11:10:16 +01:00
parent 030c6142ba
commit 8b4ef7afce
3 changed files with 31 additions and 26 deletions
+3
View File
@@ -23,3 +23,6 @@ run_test_parsing:
run_test_dfs: run_test_dfs:
PYTHONPATH=src uv run pytest tests/test_Depth.py PYTHONPATH=src uv run pytest tests/test_Depth.py
run_test_maze_gen:
PYTHONPATH=src uv run pytest tests/test_MazeGenerator.py
+13 -18
View File
@@ -94,26 +94,22 @@ class DepthFirstSearch:
path = list() path = list()
w_h = (width, height) w_h = (width, height)
coord = (0, 0) coord = (0, 0)
x, y = coord
while len(visited) < width * height: while len(visited) < width * height:
print(f"visited {len(visited)}")
x, y = coord
rand_steps = DepthFirstSearch.random_cells(visited, coord, w_h)
if len(rand_steps) == 0:
path = DepthFirstSearch.back_on_step(path, w_h, visited)
coord = path[-1]
rand_steps = DepthFirstSearch.random_cells(path, coord, w_h)
print(f"coord {coord}")
print(f"visited = {visited}")
print(f" rand steps {rand_steps}")
print(f"path = {path}")
x, y = coord
wall = DepthFirstSearch.next_step(rand_steps)
wall_r = DepthFirstSearch.reverse_path(wall)
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall)
visited = DepthFirstSearch.add_cell_visited(coord, visited) visited = DepthFirstSearch.add_cell_visited(coord, visited)
path = DepthFirstSearch.add_cell_visited(coord, path) path = DepthFirstSearch.add_cell_visited(coord, path)
random_c = DepthFirstSearch.random_cells(visited, coord, w_h)
if len(random_c) == 0:
path = DepthFirstSearch.back_on_step(path, w_h, visited)
if path:
coord = path[-1]
random_c = DepthFirstSearch.random_cells(path, coord, w_h)
x, y = coord
wall = DepthFirstSearch.next_step(random_c)
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall)
coord = DepthFirstSearch.next_cell(x, y, wall) coord = DepthFirstSearch.next_cell(x, y, wall)
print(f"coord 2 {coord}") wall_r = DepthFirstSearch.reverse_path(wall)
x, y = coord x, y = coord
maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall_r) maze[y][x] = DepthFirstSearch.broken_wall(maze[y][x], wall_r)
return maze return maze
@@ -196,11 +192,10 @@ class DepthFirstSearch:
last = path[-1] last = path[-1]
r_cells = DepthFirstSearch.random_cells(visited, last, w_h) r_cells = DepthFirstSearch.random_cells(visited, last, w_h)
while len(path) > 0: while len(path) > 0:
print(f"path {len(path)}")
path.pop() path.pop()
if path:
last = path[-1] last = path[-1]
r_cells = DepthFirstSearch.random_cells(visited, last, w_h) r_cells = DepthFirstSearch.random_cells(visited, last, w_h)
if r_cells: if r_cells:
print(f"cells {len(r_cells)}")
break break
return path return path
+13 -6
View File
@@ -1,11 +1,18 @@
import numpy import numpy
from amaz_lib.MazeGenerator import Kruskal from amaz_lib.MazeGenerator import DepthFirstSearch
def test_kruskal_output_shape() -> None: class TestMazeGenerator:
generator = Kruskal()
# def test_kruskal_output_shape() -> None:
# generator = Kruskal()
# maze = numpy.array([])
# for output in generator.generator(10, 10):
# maze = output
# assert maze.shape == (10, 10)
def test_generator(self):
maze = numpy.array([]) maze = numpy.array([])
for output in generator.generator(10, 10): maze = DepthFirstSearch.generator(10, 10)
maze = output
assert maze.shape == (10, 10) assert maze.shape == (10, 10)