From d33cd16be7100a8ece0f8d04dda1e4a0b9bd1139 Mon Sep 17 00:00:00 2001 From: The Wizard Bear <42446683+TheWizardBear@users.noreply.github.com> Date: Sun, 21 Jun 2020 15:12:12 +0100 Subject: [PATCH] replaced all occurances of this.startCell with this.startGenerationFrom --- Maze.js | 13 +++++++------ algorithms/AldousBroder.js | 4 ++-- algorithms/ModifiedPrims.js | 4 ++-- algorithms/RecursiveBacktracker.js | 4 ++-- algorithms/Sidewinder.js | 4 ++-- algorithms/SimplifiedPrims.js | 4 ++-- algorithms/Wilsons.js | 4 ++-- distances.js | 4 ++-- 8 files changed, 21 insertions(+), 20 deletions(-) diff --git a/Maze.js b/Maze.js index 2caa12d..b0ac2df 100644 --- a/Maze.js +++ b/Maze.js @@ -12,6 +12,9 @@ import solve from "./solve.js"; class Maze { constructor(mazeSettings) { + + + this.prng = mazeSettings.prng ?? Math; this.width = mazeSettings.width ?? (mazeSettings.xSize ?? (mazeSettings.height ?? 30)); @@ -34,9 +37,9 @@ class Maze { this.algorithmId === "binarytree" || this.algorithmId === "ellers" ) { - this.startGenerationFrom = "top left"; + this.startGenerationFrom = {x: 0, y: 0}; } else { - this.startGenerationFrom = mazeSettings.startGenerationFrom ?? "random"; + this.startGenerationFrom = this.getXYPosition(mazeSettings.startGenerationFrom ?? "random"); } this.prng.shuffle = (arr) => { @@ -83,11 +86,9 @@ class Maze { reset() { //random seed would go here - this.startCell = this.getXYPosition(this.startGenerationFrom); - this.currentCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.finishedGenerating = false; diff --git a/algorithms/AldousBroder.js b/algorithms/AldousBroder.js index 1d6da5b..1266683 100644 --- a/algorithms/AldousBroder.js +++ b/algorithms/AldousBroder.js @@ -16,8 +16,8 @@ class AldousBroder extends Maze { } this.currentCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.visited[this.currentCell.y][this.currentCell.x] = true; this.totalVisted = 1; diff --git a/algorithms/ModifiedPrims.js b/algorithms/ModifiedPrims.js index 39b35b9..e826e12 100644 --- a/algorithms/ModifiedPrims.js +++ b/algorithms/ModifiedPrims.js @@ -25,8 +25,8 @@ class ModifiedPrims extends Maze { this.activeCells = []; let startCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.activeCells.push(startCell); diff --git a/algorithms/RecursiveBacktracker.js b/algorithms/RecursiveBacktracker.js index 52aa620..2f32b83 100644 --- a/algorithms/RecursiveBacktracker.js +++ b/algorithms/RecursiveBacktracker.js @@ -19,8 +19,8 @@ class RecursiveBacktracker extends Maze { this.stack = []; let startCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.stack.push(startCell); this.visited[startCell.y][startCell.x] = 1; diff --git a/algorithms/Sidewinder.js b/algorithms/Sidewinder.js index c2d7e06..d72e2cd 100644 --- a/algorithms/Sidewinder.js +++ b/algorithms/Sidewinder.js @@ -3,8 +3,8 @@ import Maze from "../Maze.js"; class Sidewinder extends Maze { resetVariables() { this.currentCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.runSet = []; diff --git a/algorithms/SimplifiedPrims.js b/algorithms/SimplifiedPrims.js index 3d54806..0373e47 100644 --- a/algorithms/SimplifiedPrims.js +++ b/algorithms/SimplifiedPrims.js @@ -19,8 +19,8 @@ class SimplifiedPrims extends Maze { this.activeCells = []; let startCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.activeCells.push(startCell); diff --git a/algorithms/Wilsons.js b/algorithms/Wilsons.js index 4894bfc..319b892 100644 --- a/algorithms/Wilsons.js +++ b/algorithms/Wilsons.js @@ -13,8 +13,8 @@ class Wilsons extends Maze { this.totalVisted = 0; this.currentCell = { - x: this.startCell.x, - y: this.startCell.y, + x: this.startGenerationFrom.x, + y: this.startGenerationFrom.y, }; this.state = 0; diff --git a/distances.js b/distances.js index 9c0eb1e..ae443d3 100644 --- a/distances.js +++ b/distances.js @@ -5,9 +5,9 @@ import { export default function calculateDistances(distanceFrom) { let startPoint = this.getXYPosition( - distanceFrom ?? this.startCell ?? "top left", + distanceFrom ?? this.startGenerationFrom ?? "top left", ); - startPoint = this.cellIsInMaze(startPoint) ? startPoint : this.startCell; + startPoint = this.cellIsInMaze(startPoint) ? startPoint : this.startGenerationFrom; let Q = []; //queue let discovered = []; //keeps track of which points have been discovered so far so it doesn't loop back on itself