mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-11 09:14:29 +02:00
refactor
This commit is contained in:
@@ -1,13 +1,13 @@
|
|||||||
use <_mz_square_comm.scad>;
|
use <_mz_square_comm.scad>;
|
||||||
|
|
||||||
// is (x, y) visited?
|
// is (x, y) visited?
|
||||||
function visited(x, y, cells, columns) = cells[y][x][3];
|
function visited(x, y, cells) = cells[y][x][3];
|
||||||
|
|
||||||
// is (x, y) visitable?
|
// is (x, y) visitable?
|
||||||
function visitable(x, y, cells, rows, columns) =
|
function visitable(x, y, cells, rows, columns) =
|
||||||
y >= 0 && y < rows && // y bound
|
y >= 0 && y < rows && // y bound
|
||||||
x >= 0 && x < columns && // x bound
|
x >= 0 && x < columns && // x bound
|
||||||
!visited(x, y, cells, columns); // unvisited
|
!visited(x, y, cells); // unvisited
|
||||||
|
|
||||||
// setting (x, y) as being visited
|
// setting (x, y) as being visited
|
||||||
function set_visited(x, y, cells) =
|
function set_visited(x, y, cells) =
|
||||||
@@ -147,27 +147,28 @@ function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = fa
|
|||||||
nx_cells = set_visited(x, y, cells)
|
nx_cells = set_visited(x, y, cells)
|
||||||
)
|
)
|
||||||
// have visitable dirs?
|
// have visitable dirs?
|
||||||
len(v_dirs) == 0 ? nx_cells // road closed
|
v_dirs == [] ? nx_cells // road closed
|
||||||
: walk_around_from(
|
: walk_around_from(
|
||||||
x, y,
|
x, y,
|
||||||
v_dirs,
|
v_dirs,
|
||||||
nx_cells,
|
nx_cells,
|
||||||
rows, columns,
|
rows, columns,
|
||||||
x_wrapping, y_wrapping,
|
x_wrapping, y_wrapping,
|
||||||
|
len(v_dirs) - 1,
|
||||||
seed = seed
|
seed = seed
|
||||||
);
|
);
|
||||||
|
|
||||||
// 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, seed) =
|
||||||
// all done?
|
// all done?
|
||||||
i == len(dirs) ? cells :
|
i == -1 ? cells :
|
||||||
// not yet
|
// not yet
|
||||||
walk_around_from(x, y, dirs,
|
walk_around_from(x, y, dirs,
|
||||||
// try one direction
|
// try one direction
|
||||||
try_routes_from(x, y, dirs[i], cells, rows, columns, x_wrapping, y_wrapping, seed),
|
try_routes_from(x, y, dirs[i], cells, rows, columns, x_wrapping, y_wrapping, seed),
|
||||||
rows, columns,
|
rows, columns,
|
||||||
x_wrapping, y_wrapping,
|
x_wrapping, y_wrapping,
|
||||||
i + 1,
|
i - 1,
|
||||||
seed);
|
seed);
|
||||||
|
|
||||||
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) =
|
||||||
|
Reference in New Issue
Block a user