-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
113 lines (97 loc) · 2.49 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const node = document.querySelectorAll('.node');
const board = document.querySelector('.board');
const start = document.querySelector('.start');
const end = document.querySelector('.stop');
let node_num = 0
let nodes_on_board = [];
let BOARD = [[],[],[],[],[],[]]
let start_color = 'red';
let node_color = '#F7F6F2';
let started = false;
let clicked_n = false;
start.addEventListener('click', ()=> {
started = !started;
});
for (let i=0; i < node.length; i++){
node[i].addEventListener('click' ,() => {
if (node_num < 2 && !started){
clicked_n = !clicked_n;
if(clicked_n){
node[i].style.backgroundColor = start_color;
node_num ++;
start_color = 'black';
}else {
node[i].style.backgroundColor = node_color;
node_num --;
}
}
})
}
function update_board(){
let count = 0
let start = 0
let stop_ = 10
while (count < BOARD.length){
for (let row=start; row < stop_; row++)
{
BOARD[count].push(node[row]);
}
temp = start
start = stop_
stop_ += 10
count += 1
}
console.log(BOARD);
}
function getstart(){
for(let i=0; i<BOARD.length; i++){
for(let j=0; j< BOARD[0].length; j++){
if (BOARD[i][j].style.backgroundColor == 'red') {
return (i,j);
}
}
}
}
function isValid(pos);
function border(pos) {
}
function update_pos(initial_pos){
// look up down left and right
// if (pos is reached) {
// return true;
// }
pos = [
(0,1),
(1,0),
(-1,0),
(0,-1)
]
let x = initial_pos[0];
let y = initial_pos[1];
for(let i=0; i<positions.length; i++){
let new_x = x + pos[i];
let new_y = y + pos[i];
// if(is the rght pos){
// return true;
// }
if(isValid((new_x,new_y)) && !border((new_x,new_y))){
new_pos = (new_x,new_y);
BOARD[new_pos[0]][new_pos[1]].style.backgroundColor = 'red';
update_pos(new_pos);
}
else if(!isValid((new_x,new_y)) || border((new_x,new_y))) {
continue;
}
}
}
function main(pos){
update_board();
console.log(BOARD);
for(let i=0; i<BOARD.length; i++){
for(let j=0; j< BOARD[0].length; j++){
BOARD[i][j].style.backgroundColor = 'pink';
}
}
// update_pos(pos);
}
main();