-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.26 KB
/
index.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
const canvas = document.getElementById('gridCanvas');
const context = canvas.getContext('2d');
const gridSize = 50;
function loadImage(src) {
return new Promise((resolve) => {
const img = new Image();
img.src = src;
img.onload = () => resolve(img);
});
}
async function loadImages() {
const images = {
floor: await loadImage("images/floor.png"),
wall: await loadImage("images/wall.png"),
box: await loadImage("images/box.png"),
goal: await loadImage("images/goal.png"),
player: await loadImage("images/keeper.png"),
playerOnGoal: await loadImage("images/keeper_on_goal.png"),
boxOnGoal: await loadImage("images/box_on_goal.png"),
};
return images;
}
let game;
let bfs, dfs, idfs;
async function newGame(level) {
const images = await loadImages();
game = new Game(level, images);
bfs = new BFS(game);
dfs = new DFS(game);
idfs = new IDFS(game);
}
function solve(algorithm) {
game.isSolving = true
switch (algorithm) {
case 'bfs':
bfs.solve();
break;
case 'dfs':
dfs.solve();
break;
case 'idfs':
idfs.solve();
break;
}
game.isSolving = false
}
newGame(1);