Skip to content

Commit

Permalink
replaced all occurances of this.startCell with this.startGenerationFrom
Browse files Browse the repository at this point in the history
  • Loading branch information
mjrlowe committed Jun 21, 2020
1 parent 2c99a2d commit d33cd16
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 20 deletions.
13 changes: 7 additions & 6 deletions Maze.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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) => {
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions algorithms/AldousBroder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions algorithms/ModifiedPrims.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions algorithms/RecursiveBacktracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions algorithms/Sidewinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions algorithms/SimplifiedPrims.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions algorithms/Wilsons.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions distances.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d33cd16

Please sign in to comment.