Skip to content

Commit c7a81d0

Browse files
committed
formatted files
1 parent b19901b commit c7a81d0

17 files changed

Lines changed: 111 additions & 89 deletions

Maze.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,39 @@ class Maze {
1414
constructor(mazeSettings) {
1515
this.prng = mazeSettings.prng ?? Math;
1616
this.width = mazeSettings.width ||
17-
mazeSettings.xSize || mazeSettings.size || mazeSettings.height || mazeSettings.ySize || 30;
17+
mazeSettings.xSize || mazeSettings.size || mazeSettings.height ||
18+
mazeSettings.ySize || 30;
1819
this.height = mazeSettings.height ||
1920
mazeSettings.ySize || mazeSettings.size || this.width;
2021
this.finishedGenerating = false;
2122
this.seed = mazeSettings.seed ?? Math.floor(Math.random() * 10e8);
2223
this.algorithm = mazeSettings.algorithm;
2324
this.algorithmId = mazeSettings.algorithmId;
24-
25+
2526
this.entrance = this.getXYPosition(mazeSettings.entrance ?? "top left");
2627

2728
this.exit = this.getXYPosition(mazeSettings.exit ?? "bottom right");
2829

29-
this.entrance.direction = this.entrance.direction ?? (this.entrance.x <= 0 ? "W" : this.entrance.x >= this.width-1 ? "E" : this.entrance.y <= 0 ? "N" : this.entrance.y >= this.width-1 ? "S" : " ");
30-
this.exit.direction = this.exit.direction ?? (this.exit.x <= 0 ? "W" : this.exit.x >= this.width-1 ? "E" : this.exit.y <= 0 ? "N" : this.exit.y >= this.width-1 ? "S" : " ");
30+
this.entrance.direction = this.entrance.direction ??
31+
(this.entrance.x <= 0
32+
? "W"
33+
: this.entrance.x >= this.width - 1
34+
? "E"
35+
: this.entrance.y <= 0
36+
? "N"
37+
: this.entrance.y >= this.width - 1
38+
? "S"
39+
: " ");
40+
this.exit.direction = this.exit.direction ??
41+
(this.exit.x <= 0
42+
? "W"
43+
: this.exit.x >= this.width - 1
44+
? "E"
45+
: this.exit.y <= 0
46+
? "N"
47+
: this.exit.y >= this.width - 1
48+
? "S"
49+
: " ");
3150

3251
if (
3352
this.algorithmId === "sidewinder" ||
@@ -106,7 +125,7 @@ class Maze {
106125
}
107126

108127
step() {
109-
if(this.finishedGenerating) return false;
128+
if (this.finishedGenerating) return false;
110129
this.takeStep();
111130
return !this.finishedGenerating;
112131
}

algorithms/10Print.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,39 @@ import Maze from "../Maze.js";
22
import {
33
opposite,
44
dx,
5-
dy
5+
dy,
66
} from "../directions.js";
77

88
class TenPrint extends Maze {
99
resetVariables() {
1010
this.currentCell = {
1111
x: 0,
12-
y: 0
13-
}
12+
y: 0,
13+
};
1414
this.allowOutsideConnections = false;
1515
}
1616

1717
takeStep() {
1818
let passageDirection = this.prng.random() < 0.5 ? "S" : "E";
1919
let neighbor1 = {
2020
x: this.currentCell.x + dx[passageDirection],
21-
y: this.currentCell.y + dy[passageDirection]
21+
y: this.currentCell.y + dy[passageDirection],
2222
};
2323
let neighbor2 = {
2424
x: this.currentCell.x + dx[opposite[passageDirection]],
25-
y: this.currentCell.y + dy[opposite[passageDirection]]
25+
y: this.currentCell.y + dy[opposite[passageDirection]],
2626
};
27-
27+
2828
if (this.cellIsInMaze(neighbor1) || this.allowOutsideConnections) {
2929
this.removeWall({
3030
x: this.currentCell.x,
31-
y: this.currentCell.y
31+
y: this.currentCell.y,
3232
}, passageDirection);
3333
}
3434
if (this.cellIsInMaze(neighbor2) || this.allowOutsideConnections) {
3535
this.removeWall({
3636
x: this.currentCell.x,
37-
y: this.currentCell.y
37+
y: this.currentCell.y,
3838
}, opposite[passageDirection]);
3939
}
4040

@@ -44,10 +44,7 @@ class TenPrint extends Maze {
4444
this.currentCell.x = this.currentCell.y % 2;
4545
if (this.currentCell.y >= this.height) this.finishedGenerating = true;
4646
}
47-
4847
}
49-
5048
}
5149

52-
53-
export default TenPrint;
50+
export default TenPrint;

algorithms/AldousBroder.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class AldousBroder extends Maze {
2525

2626
//called every time the maze needs to be updated
2727
takeStep() {
28-
2928
let possibleDirections = [];
3029
if (this.currentCell.y !== 0) possibleDirections.push("N");
3130
if (this.currentCell.y !== this.height - 1) possibleDirections.push("S");
@@ -54,7 +53,6 @@ class AldousBroder extends Maze {
5453
if (this.totalVisted >= this.width * this.height) {
5554
this.finishedGenerating = true;
5655
}
57-
5856
}
5957
}
6058

algorithms/BinaryTree.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ class BinaryTree extends Maze {
2222
) {
2323
this.finishedGenerating = true;
2424
}
25-
2625
}
2726
}
2827

algorithms/Ellers.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ class Eller extends Maze {
7575
}
7676

7777
takeStep() {
78-
7978
if (this.mode === this.HORIZONTAL) {
8079
this.horizontalStep();
8180
} else {
8281
this.verticalStep();
8382
}
84-
8583
}
8684
}
8785

algorithms/HuntAndKill.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class HuntAndKill extends Maze {
2323
}
2424

2525
takeStep() {
26-
2726
//random walk
2827
if (!this.hunting) {
2928
this.visited[this.currentCell.y][this.currentCell.x] = true;
@@ -149,7 +148,6 @@ class HuntAndKill extends Maze {
149148
}
150149
}
151150
}
152-
153151
}
154152
}
155153

algorithms/Kruskals.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class Kruskals extends Maze {
3232
}
3333

3434
takeStep() {
35-
3635
let edge = this.edges.pop();
3736
let cell1 = {
3837
x: edge.x,
@@ -57,7 +56,6 @@ class Kruskals extends Maze {
5756
}
5857

5958
if (this.edges.length === 0) this.finishedGenerating = true;
60-
6159
}
6260

6361
getCellIndex(cell) {

algorithms/ModifiedPrims.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ class ModifiedPrims extends Maze {
3434
}
3535

3636
takeStep() {
37-
3837
//find index of cell with minimum cost
3938
let minCost = Infinity;
4039
let cellIndex = 0;
@@ -80,7 +79,6 @@ class ModifiedPrims extends Maze {
8079
}
8180

8281
if (this.activeCells.length === 0) this.finishedGenerating = true;
83-
8482
}
8583
}
8684

algorithms/RecursiveDivision.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class RecursiveDivision extends Maze {
3838
}
3939

4040
takeStep() {
41-
4241
switch (this.state) {
4342
case this.CHOOSE_REGION:
4443
this.chooseRegion();
@@ -55,7 +54,6 @@ class RecursiveDivision extends Maze {
5554
this.state,
5655
);
5756
}
58-
5957
}
6058

6159
chooseRegion() {

algorithms/Sidewinder.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class Sidewinder extends Maze {
4646
if (this.currentCell.y >= this.height) {
4747
this.finishedGenerating = true;
4848
}
49-
5049
}
5150
}
5251

0 commit comments

Comments
 (0)