1
0
mirror of https://github.com/JustinSDK/dotSCAD.git synced 2025-08-12 09:44:16 +02:00
This commit is contained in:
Justin Lin
2022-03-18 14:34:27 +08:00
parent 2cd56758eb
commit 7d1cbb9460

View File

@@ -144,30 +144,25 @@ function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = fa
let( let(
r_dirs = rand_dirs(x * rows + y, seed), r_dirs = rand_dirs(x * rows + y, seed),
v_dirs = visitable_dirs(r_dirs, x, y, cells, rows, columns, x_wrapping, y_wrapping), v_dirs = visitable_dirs(r_dirs, x, y, cells, rows, columns, x_wrapping, y_wrapping),
nx_cells = set_visited(x, y, cells) nx_cells0 = set_visited(x, y, cells),
leng_v_dirs = len(v_dirs)
) )
// have visitable dirs? // have visitable dirs?
v_dirs == [] ? nx_cells // road closed leng_v_dirs == 0 ? nx_cells0 : // road closed
: walk_around_from( // try four directions
x, y, let(nxcells1 = next_cells(x, y, v_dirs[0], nx_cells0, rows, columns, x_wrapping, y_wrapping, seed))
v_dirs, leng_v_dirs == 1 ? nxcells1 :
nx_cells, let(nxcells2 = next_cells(x, y, v_dirs[1], nxcells1, rows, columns, x_wrapping, y_wrapping, seed))
rows, columns, leng_v_dirs == 2 ? nxcells2 :
x_wrapping, y_wrapping, let(nxcells3 = next_cells(x, y, v_dirs[2], nxcells2, rows, columns, x_wrapping, y_wrapping, seed))
len(v_dirs) - 1, leng_v_dirs == 3 ? nxcells3 : next_cells(x, y, v_dirs[3], nxcells3, rows, columns, x_wrapping, y_wrapping, seed);
seed = seed
);
// try four directions function next_cells(x, y, dir, cells, rows, columns, x_wrapping, y_wrapping, seed) =
function walk_around_from(x, y, dirs, cells, rows, columns, x_wrapping, y_wrapping, i, seed) =
// all done?
i == -1 ? cells :
// not yet
let( let(
dir = dirs[i],
nx = next_x(x, dir, columns, x_wrapping), nx = next_x(x, dir, columns, x_wrapping),
ny = next_y(y, dir, rows, y_wrapping), ny = next_y(y, dir, rows, y_wrapping)
nx_cells = !visitable(nx, ny, cells, rows, columns) ? // is the dir visitable? )
!visitable(nx, ny, cells, rows, columns) ? // is the dir visitable?
cells : // road closed so return cells directly cells : // road closed so return cells directly
go_maze( // try the cell go_maze( // try the cell
nx, ny, nx, ny,
@@ -175,12 +170,4 @@ function walk_around_from(x, y, dirs, cells, rows, columns, x_wrapping, y_wrappi
rows, columns, rows, columns,
x_wrapping, y_wrapping, x_wrapping, y_wrapping,
seed seed
) );
)
walk_around_from(x, y, dirs,
// try one direction
nx_cells,
rows, columns,
x_wrapping, y_wrapping,
i - 1,
seed);