-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoPlay.js
37 lines (34 loc) · 1.12 KB
/
autoPlay.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
stack2 = [];
function autoPlay(){
a = true;
check = 2;
stack3 = [];
if(!current.walls[0] && !grid[index(current.i, current.j-1)].traversed){//top
stack3.push(grid[index(current.i, current.j-1)]);
}
if(!current.walls[1] && !grid[index(current.i+1, current.j)].traversed){//right
stack3.push(grid[index(current.i+1, current.j)]);
}
if(!current.walls[2] && !grid[index(current.i, current.j+1)].traversed){//bottom
stack3.push(grid[index(current.i, current.j+1)]);
}
if(!current.walls[3] && !grid[index(current.i-1, current.j)].traversed){//left
stack3.push(grid[index(current.i-1, current.j)]);
}
if(current === grid[0]){
for(var g=0; g<grid.length; g++){
grid[g].traversed = false;
}
}
if(stack3.length>0){
stack2.push(current);
current.visited = false;
current.traversed = true;
current = stack3[floor(random(0, stack3.length-1))];
}
else if(stack2.length>0 && stack3.length === 0){
current.traversed = true;
current = stack2.pop();
current.visited = true;
}
}