mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-14 10:44:48 +02:00
refactor
This commit is contained in:
@@ -109,15 +109,15 @@ function visitable_dirs(r_dirs, x, y, cells, rows, columns, x_wrapping, y_wrappi
|
|||||||
function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = false, seed) =
|
function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = false, seed) =
|
||||||
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)
|
||||||
)
|
)
|
||||||
// have visitable dirs?
|
// have visitable dirs?
|
||||||
len(v_dirs) == 0 ?
|
len(v_dirs) == 0 ? nx_cells // road closed
|
||||||
set_visited(x, y, cells) // road closed
|
|
||||||
: walk_around_from(
|
: walk_around_from(
|
||||||
x, y,
|
x, y,
|
||||||
v_dirs,
|
v_dirs,
|
||||||
set_visited(x, y, cells),
|
nx_cells,
|
||||||
rows, columns,
|
rows, columns,
|
||||||
x_wrapping, y_wrapping,
|
x_wrapping, y_wrapping,
|
||||||
seed = seed
|
seed = seed
|
||||||
@@ -126,7 +126,7 @@ function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = fa
|
|||||||
// try four directions
|
// try four directions
|
||||||
function walk_around_from(x, y, dirs, cells, rows, columns, x_wrapping, y_wrapping, i = 0, seed) =
|
function walk_around_from(x, y, dirs, cells, rows, columns, x_wrapping, y_wrapping, i = 0, seed) =
|
||||||
// all done?
|
// all done?
|
||||||
i < len(dirs) ?
|
i == len(dirs) ? cells :
|
||||||
// not yet
|
// not yet
|
||||||
walk_around_from(x, y, dirs,
|
walk_around_from(x, y, dirs,
|
||||||
// try one direction
|
// try one direction
|
||||||
@@ -134,12 +134,13 @@ 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,
|
||||||
i + 1,
|
i + 1,
|
||||||
seed)
|
seed);
|
||||||
: cells;
|
|
||||||
|
|
||||||
function try_routes_from(x, y, dir, cells, rows, columns, x_wrapping, y_wrapping, seed) =
|
function try_routes_from(x, y, dir, cells, rows, columns, x_wrapping, y_wrapping, seed) =
|
||||||
// is the dir visitable?
|
// is the dir visitable?
|
||||||
visitable(next_x(x, dir, columns, x_wrapping), next_y(y, dir, rows, y_wrapping), cells, rows, columns) ?
|
!visitable(next_x(x, dir, columns, x_wrapping), next_y(y, dir, rows, y_wrapping), cells, rows, columns) ?
|
||||||
|
// road closed so return cells directly
|
||||||
|
cells :
|
||||||
// try the cell
|
// try the cell
|
||||||
go_maze(
|
go_maze(
|
||||||
next_x(x, dir, columns, x_wrapping), next_y(y, dir, rows, y_wrapping),
|
next_x(x, dir, columns, x_wrapping), next_y(y, dir, rows, y_wrapping),
|
||||||
@@ -147,6 +148,4 @@ function try_routes_from(x, y, dir, cells, rows, columns, x_wrapping, y_wrapping
|
|||||||
rows, columns,
|
rows, columns,
|
||||||
x_wrapping, y_wrapping,
|
x_wrapping, y_wrapping,
|
||||||
seed
|
seed
|
||||||
)
|
);
|
||||||
// road closed so return cells directly
|
|
||||||
: cells;
|
|
Reference in New Issue
Block a user