From 2cd56758ebcd561869b26509d8533e96ead76407 Mon Sep 17 00:00:00 2001 From: Justin Lin Date: Fri, 18 Mar 2022 13:08:33 +0800 Subject: [PATCH] refactor --- src/maze/_impl/_mz_square_cells_impl.scad | 44 +++++++++++------------ 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/maze/_impl/_mz_square_cells_impl.scad b/src/maze/_impl/_mz_square_cells_impl.scad index 2bfce435..62c2a3ae 100644 --- a/src/maze/_impl/_mz_square_cells_impl.scad +++ b/src/maze/_impl/_mz_square_cells_impl.scad @@ -162,25 +162,25 @@ function go_maze(x, y, cells, rows, columns, x_wrapping = false, y_wrapping = fa function walk_around_from(x, y, dirs, cells, rows, columns, x_wrapping, y_wrapping, i, seed) = // all done? i == -1 ? cells : - // not yet - walk_around_from(x, y, dirs, - // try one direction - try_routes_from(x, y, dirs[i], cells, rows, columns, x_wrapping, y_wrapping, seed), - rows, columns, - x_wrapping, y_wrapping, - i - 1, - seed); - -function try_routes_from(x, y, dir, cells, rows, columns, x_wrapping, y_wrapping, seed) = - // is the dir visitable? - !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 - go_maze( - next_x(x, dir, columns, x_wrapping), next_y(y, dir, rows, y_wrapping), - carve(dir, x, y, cells, rows, columns), - rows, columns, - x_wrapping, y_wrapping, - seed - ); \ No newline at end of file + // not yet + let( + dir = dirs[i], + nx = next_x(x, dir, columns, x_wrapping), + ny = next_y(y, dir, rows, y_wrapping), + nx_cells = !visitable(nx, ny, cells, rows, columns) ? // is the dir visitable? + cells : // road closed so return cells directly + go_maze( // try the cell + nx, ny, + carve(dir, x, y, cells, rows, columns), + rows, columns, + x_wrapping, y_wrapping, + seed + ) + ) + walk_around_from(x, y, dirs, + // try one direction + nx_cells, + rows, columns, + x_wrapping, y_wrapping, + i - 1, + seed); \ No newline at end of file