+
+
+
{/* Zoom settings island */}
=
+ settings.generationAlgorithm === "random"
+ ? randomFromArray(GENERATION_ALGORITHMS.filter((x) => x !== "random"))
+ : settings.generationAlgorithm;
+ const alg: MazeGenerator = match(algType)
+ .with("backtracker", () => new Backtracker({ rows, cols }))
+ .with("wilsons", () => new Wilsons({ rows, cols }))
+ .with("prims", () => new Prims({ rows, cols }))
+ .exhaustive();
this.maze = alg.maze;
this.drawer.maze = this.maze;
@@ -165,7 +163,14 @@ export class MazeController {
const [start, end] = this.randomStartEnd();
this.drawer.startEnd = [start, end];
- const alg: MazeSolver = new BFS(this.maze, start, end);
+ const algType: Exclude =
+ settings.solveAlgorithm === "random"
+ ? randomFromArray(SOLVE_ALGORITHMS.filter((x) => x !== "random"))
+ : settings.solveAlgorithm;
+ const alg: MazeSolver = match(algType)
+ .with("bfs", () => new BFS(this.maze!, start, end))
+ .with("tremaux", () => new Tremaux(this.maze!, start, end))
+ .exhaustive();
if (settings.doAnimateSolving) {
if (this.shouldSweep) {
diff --git a/src/lib/MazeDrawer.ts b/src/lib/MazeDrawer.ts
index 00f552a..7f89900 100644
--- a/src/lib/MazeDrawer.ts
+++ b/src/lib/MazeDrawer.ts
@@ -1,14 +1,9 @@
import colors from "tailwindcss/colors";
import { match } from "ts-pattern";
import { AnimationPromise } from "./AnimationPromise";
+import type { MazeDimensions, MazeEvent } from "./maze";
import { type MazeCell } from "./MazeCell";
-import { type MazeDimensions, type MazeEvent } from "./MazeController";
-import {
- type RectSize,
- type Coord,
- type GridSize,
- type Idx2d,
-} from "./twoDimens";
+import type { Coord, GridSize, Idx2d, RectSize } from "./twoDimens";
import { clamp, easeOutQuad, type Direction } from "./utils";
/** Colors used by the renderer. */
diff --git a/src/lib/algorithms/algorithmTypes.ts b/src/lib/algorithms/algorithmTypes.ts
deleted file mode 100644
index 0b73c49..0000000
--- a/src/lib/algorithms/algorithmTypes.ts
+++ /dev/null
@@ -1,7 +0,0 @@
-export type GenerationAlgorithm =
- | "backtracking"
- | "prims"
- | "wilsons"
- | "kruskals";
-
-export type SolveAlgorithm = "tremaux" | "astar" | "breadth";
diff --git a/src/lib/algorithms/algorithms.ts b/src/lib/algorithms/algorithms.ts
new file mode 100644
index 0000000..4a289ca
--- /dev/null
+++ b/src/lib/algorithms/algorithms.ts
@@ -0,0 +1,9 @@
+import { Backtracker } from "./generating/Backtracking";
+import { MazeGenerator } from "./generating/MazeGenerator";
+import { Prims } from "./generating/Prims";
+import { Wilsons } from "./generating/Wilsons";
+import { BFS } from "./solving/BFS";
+import { MazeSolver } from "./solving/MazeSolver";
+import { Tremaux } from "./solving/Tremaux";
+
+export { Backtracker, BFS, MazeGenerator, MazeSolver, Prims, Tremaux, Wilsons };
diff --git a/src/lib/algorithms/generating/Backtracking.ts b/src/lib/algorithms/generating/Backtracking.ts
index 6235576..dea2721 100644
--- a/src/lib/algorithms/generating/Backtracking.ts
+++ b/src/lib/algorithms/generating/Backtracking.ts
@@ -8,7 +8,7 @@ import { randomFromArray } from "@/lib/utils";
* Randomly connects to unvisited nodes until it hits a dead end, then it
* backtracks. This is a recursive algorithm, but it's implemented iteratively.
*/
-export class Backtracking extends MazeGenerator {
+export class Backtracker extends MazeGenerator {
private exploreStack: MazeCell[] = [];
protected _step(): [boolean, Readonly[]] {
diff --git a/src/lib/maze.ts b/src/lib/maze.ts
new file mode 100644
index 0000000..2045f5f
--- /dev/null
+++ b/src/lib/maze.ts
@@ -0,0 +1,29 @@
+export const GENERATION_ALGORITHMS = [
+ "random",
+ "wilsons",
+ "backtracker",
+ "prims",
+] as const;
+export type GenerationAlgorithm = (typeof GENERATION_ALGORITHMS)[number];
+export const SOLVE_ALGORITHMS = ["random", "bfs", "tremaux"] as const;
+export type SolveAlgorithm = (typeof SOLVE_ALGORITHMS)[number];
+export type MazeEvent = "generate" | "solve";
+
+export interface MazeDimensions {
+ rows: number;
+ cols: number;
+ /**
+ * Width of cell vs wall.
+ *
+ * E.g., 0.5 means a cell is half the width of a wall.
+ */
+ cellWallRatio: number;
+}
+
+export interface MazeSettings {
+ dimensions: MazeDimensions;
+ generationAlgorithm: GenerationAlgorithm;
+ doAnimateGenerating: boolean;
+ solveAlgorithm: SolveAlgorithm;
+ doAnimateSolving: boolean;
+}