-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrunMazeAlgorithm.ts
42 lines (41 loc) · 1.15 KB
/
runMazeAlgorithm.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { binaryTree } from "../lib/algorithms/maze/binaryTree";
import recursiveDivision from "../lib/algorithms/maze/recursiveDivision";
import { MAX_COLS, MAX_ROWS, SPEEDS } from "./constants";
import { constructBorder } from "./constructBorder";
import { GridType, MazeType, SpeedType, TileType } from "./types";
export const runMazeAlgorithm = async ({
maze,
grid,
startTile,
endTile,
setIsDisabled,
speed,
}: {
maze: MazeType;
grid: GridType;
startTile: TileType;
endTile: TileType;
setIsDisabled: (isDisabled: boolean) => void;
speed: SpeedType;
}) => {
if (maze == "BINARY_TREE") {
await binaryTree(grid, startTile, endTile, setIsDisabled, speed);
} else if (maze === "RECURSIVE_DIVISION") {
const currentSpeed = SPEEDS.find((s) => s.value === speed)!.value ?? 2;
await constructBorder(grid, startTile, endTile);
await recursiveDivision({
grid,
startTile,
endTile,
row: 1,
col: 1,
height: Math.floor((MAX_ROWS - 1) / 2),
width: Math.floor((MAX_COLS - 1) / 2),
setIsDisabled,
speed,
});
setTimeout(() => {
setIsDisabled(false);
}, 800 * currentSpeed);
}
};