-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
80 lines (63 loc) · 1.63 KB
/
main.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
let maze
// const rowCount = 20
// const colCount = 62
let startNode, endNode
const rowCount = 20
const colCount = 20
let getId = (i, j) => {
return i +"-"+j
}
let getrowId = (i) =>{
return "row " + i
}
let getStyle = (i, j, rows, cols) => {
return ""
}
preCompute()
function preCompute(){
maze = new Maze(rowCount, colCount)
maze.setStartNode(Math.floor(rowCount/4),Math.floor(colCount/4))
maze.setEndNode(Math.floor(rowCount/4),Math.floor(3 *colCount/4))
// generateMaze()
}
function start(){
let algoUsed = document.getElementById("algoUsed").value
switch(algoUsed){
case "bfs":
BFSsearch(maze, maze.startNode, maze.endNode)
break
case "dijkstra":
dijkstraSearch(maze, maze.startNode, maze.endNode)
break
case "astar":
AstarSearch(maze, maze.startNode, maze.endNode)
break
case "dfs":
DFSsearch(maze, maze.startNode, maze.endNode)
break
}
}
function updateInput(){
}
function generateMaze(){
newMaze()
maze.matrix.forEach(row => {
row.forEach(node => {
node.addWall(0)
node.addWall(1)
node.addWall(2)
node.addWall(3)
node.addClass("wall")
})
})
createMazeGoTo(maze.matrix[0][0], "up")
}
// function to clear all visited non visited for new algorithm
function clearMaze(){
maze.clearMaze()
}
function newMaze(){
maze.newMaze()
maze.setStartNode(Math.floor(rowCount/4),Math.floor(colCount/4))
maze.setEndNode(Math.floor(rowCount/4),Math.floor(3 *colCount/4))
}