From 539a272a20e5a8d963b6eb728938482ff4f7a4e8 Mon Sep 17 00:00:00 2001 From: The Wizard Bear <42446683+TheWizardBear@users.noreply.github.com> Date: Sun, 13 Sep 2020 17:08:40 +0100 Subject: [PATCH] formatted files --- Maze.js | 6 +++--- algorithms/Wilsons.js | 44 +++++++++++++++++++++---------------------- examples/local.js | 2 +- mod.js | 4 ++-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/Maze.js b/Maze.js index e672688..2eb1820 100644 --- a/Maze.js +++ b/Maze.js @@ -140,9 +140,9 @@ class Maze { case "ellers": return new Maze.algorithms.Ellers(settings); - case "wilson": - case "wilsons": - return new Maze.algorithms.Wilsons(settings); + case "wilson": + case "wilsons": + return new Maze.algorithms.Wilsons(settings); default: throw "Invalid algorithm"; diff --git a/algorithms/Wilsons.js b/algorithms/Wilsons.js index 8ed9728..ecb0e45 100644 --- a/algorithms/Wilsons.js +++ b/algorithms/Wilsons.js @@ -3,7 +3,7 @@ import { dx, dy, opposite, - directions + directions, } from "../directions.js"; class Wilsons extends Maze { @@ -16,7 +16,7 @@ class Wilsons extends Maze { this.visited[y][x] = false; this.unvisited.push({ x, - y + y, }); } } @@ -29,62 +29,62 @@ class Wilsons extends Maze { } takeStep() { - //pick a random cell to start a new path this.currentCell = this.unvisited[Math.floor(this.prng.random() * this.unvisited.length)]; let path = [this.currentCell]; - + while (!this.visited[this.currentCell.y][this.currentCell.x]) { let validNeighbours = []; for (let direction of directions) { let neighbour = { x: this.currentCell.x + dx[direction], y: this.currentCell.y + dy[direction], - direction - } - if(this.cellIsInMaze(neighbour)) validNeighbours.push(neighbour) + direction, + }; + if (this.cellIsInMaze(neighbour)) validNeighbours.push(neighbour); } - let newCell = validNeighbours[Math.floor(this.prng.random() * validNeighbours.length)]; + let newCell = + validNeighbours[ + Math.floor(this.prng.random() * validNeighbours.length) + ]; let cellVisited = false; let cellPreviousIndex = -1; path.forEach((pathCell, index) => { - if(pathCell.x === newCell.x && pathCell.y === newCell.y){ + if (pathCell.x === newCell.x && pathCell.y === newCell.y) { cellVisited = true; cellPreviousIndex = index; } - }) + }); - if(!cellVisited ){ - path.push(newCell) + if (!cellVisited) { + path.push(newCell); this.currentCell = newCell; - }else{ + } else { this.currentCell = path[cellPreviousIndex]; - path = path.slice(0, cellPreviousIndex+1) + path = path.slice(0, cellPreviousIndex + 1); } } - for(let cell of path){ - this.removeWall({x: cell.x, y: cell.y}, opposite[cell.direction]) - this.markAsVisited(cell) + for (let cell of path) { + this.removeWall({ x: cell.x, y: cell.y }, opposite[cell.direction]); + this.markAsVisited(cell); } if (this.unvisited.length === 0) this.finishedGenerating = true; } markAsVisited(newlyVisitedCell) { - this.visited[newlyVisitedCell.y][newlyVisitedCell.x] = true; this.unvisited.forEach(( cell, - index + index, ) => { if (cell.x === newlyVisitedCell.x && cell.y === newlyVisitedCell.y) { this.unvisited.splice(index, 1); } - - }) + }); } } -export default Wilsons; \ No newline at end of file +export default Wilsons; diff --git a/examples/local.js b/examples/local.js index a9fe540..7ac55e0 100644 --- a/examples/local.js +++ b/examples/local.js @@ -14,4 +14,4 @@ let m = Maze.create(mazeSettings); m.generate(); //print it to the console -m.printString(); \ No newline at end of file +m.printString(); diff --git a/mod.js b/mod.js index 8e84c4b..e84f9be 100644 --- a/mod.js +++ b/mod.js @@ -31,7 +31,7 @@ Maze.algorithms = { BinaryTree, TruePrims, TenPrint, - Wilsons + Wilsons, }; -export { Maze }; +export { Maze };