-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwinnerBot.js
More file actions
55 lines (45 loc) · 1.75 KB
/
winnerBot.js
File metadata and controls
55 lines (45 loc) · 1.75 KB
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
class Bot {
makeMove(gamestate) {
let result = "";
if (gamestate.rounds.length === 0) {
this.dynamite = 100;
this.round = 0;
this.rocksPlayed = 0;
this.paperPlayed = 0;
this.sissorPlayed = 0;
this.waterBombsPlayed = 0;
}
//console.log(this.round);
if (gamestate.rounds.length > 0) {
//console.log(gamestate.rounds[this.round-1].p2);
if (gamestate.rounds[this.round - 1].p2 === 'R')
this.rocksPlayed++;
else if (gamestate.rounds[this.round - 1].p2 === 'P')
this.paperPlayed++;
else if (gamestate.rounds[this.round - 1].p2 === 'S')
this.sissorPlayed++;
else if (gamestate.rounds[this.round - 1].p2 === 'W')
this.waterBombsPlayed++;
}
if (this.rocksPlayed > this.paperPlayed || this.rocksPlayed > this.sissorPlayed || this.rocksPlayed > this.waterBombsPlayed) {
return 'P';
} else if (this.paperPlayed > this.rocksPlayed || this.paperPlayed > this.sissorPlayed || this.paperPlayed > this.waterBombsPlayed) {
return 'S';
} else if (this.sissorPlayed > this.rocksPlayed || this.sissorPlayed > this.paperPlayed || this.sissorPlayed > this.waterBombsPlayed) {
return 'R';
}
this.round++;
if (Math.floor(Math.random() * 5) === 5) {
if (this.dynamite > 0 && this.dynamite <= 100) {
this.dynamite--;
return 'D';
}
}
else {
let char = "PWRS";
result = char.charAt(Math.floor(Math.random() * 4));
return result;
}
}
}
module.exports = new Bot();