-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.js
58 lines (54 loc) · 1.1 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
57
58
function GameOver(knight) {
end = 0;
knight.forEach(function(item) {
if (item.health < 1) {
++end;
}
})
return end > 4 ? true : false;
}
knight = [{
name: 'k1',
health: 100
}, {
name: 'k2',
health: 100
}, {
name: 'k3',
health: 100
}, {
name: 'k4',
health: 100
}, {
name: 'k5',
health: 100
}, {
name: 'k6',
health: 100
}];
while (true) {
if (GameOver(knight)) {
break;
}
disorder = [
[1, 2, 3, 4, 5],
[2, 3, 4, 5, 0],
[3, 4, 5, 0, 1],
[4, 5, 0, 1, 2],
[5, 0, 1, 2, 3],
[0, 1, 2, 3, 4]
]
for (j = 0; j < 6; j++) {
for (i = 0; i < 6; i++) {
struc = disorder[j];
if (knight[j].health > 0 && knight[struc[i]].health > 0) {
irand = Math.floor(Math.random() * 6) + 1;
knight[struc[i]].health = knight[struc[i]].health - irand;
break;
}
}
}
}
console.log(knight);
let winner= knight.find(winner=>winner.health>0);
console.log("winner is" +" " + winner.name);