Skip to content

Commit

Permalink
maze: Per TODO, lock the exit in when drawing to the bottom (that was…
Browse files Browse the repository at this point in the history
… easy)
  • Loading branch information
Rosuav committed Jun 27, 2024
1 parent 56924ee commit a30a601
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions maze.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ function adjacent(r, c, dir) {

let interval, start = +new Date;
function improve_maze(maze, walk, fast) {
let preferred_exit = -1;
if (fast && walk.length > 1 && walk[walk.length - 1][0] === maze.length - 1) preferred_exit = walk[walk.length - 1][1];
do { //In fast mode, keep going till the maze is fully generated, THEN render.
if (!walk.length) {
//Initialize our random walk with a cell at the top of the grid,
Expand All @@ -63,7 +65,7 @@ function improve_maze(maze, walk, fast) {
walk.pop();
if (!walk.length) {
//We've walked all the way back to the start, all is done! Pick an exit and mark it.
const exit = Math.floor(Math.random() * maze[0].length);
const exit = preferred_exit === -1 ? Math.floor(Math.random() * maze[0].length) : preferred_exit;
maze[maze.length - 1][exit] = maze[maze.length - 1][exit].split(" ").filter(w => w !== "wb").join(" ") + " exit";
clearInterval(interval); interval = 0;
//Mark the entrance as part of the path.
Expand Down Expand Up @@ -162,7 +164,6 @@ on("click", "#draw", e => {
console.log(url.toString());
start = +new Date;
improve_maze(rendered_maze, drawing, 1);
//TODO: If the last cell of drawing was on the bottom row, make it the exit.
drawing = null;
return;
}
Expand Down Expand Up @@ -212,7 +213,6 @@ function decode_token(token) {
}
start = +new Date;
improve_maze(maze, drawing, 1);
//TODO: If the last cell of drawing was on the bottom row, make it the exit.
}
if (location.hash.length > 3) decode_token(location.hash.slice(1));
else generate(1);
Expand Down

0 comments on commit a30a601

Please sign in to comment.