-
Notifications
You must be signed in to change notification settings - Fork 3
/
HumanAgent.js
100 lines (91 loc) · 3.18 KB
/
HumanAgent.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
class HumanAgent extends Agent {
constructor(upKey, downKey, leftKey, rightKey, shootKey) {
super();
this.upKey = upKey;
this.downKey = downKey;
this.leftKey = leftKey;
this.rightKey = rightKey;
this.shootKey = shootKey;
}
act() {
let up = (keys[this.upKey]) ? true : false;
let down = (keys[this.downKey]) ? true : false;
let left = (keys[this.leftKey]) ? true : false;
let right = (keys[this.rightKey]) ? true : false;
let shoot = (keys[this.shootKey]) ? true : false;
this.shoot = shoot & !this.pastShoot;
let actionH = ActionH.nomove;
if (left) {
actionH = this.side == Side.red ? ActionH.backward : ActionH.forward;
} else if (right) {
actionH = this.side == Side.red ? ActionH.forward : ActionH.backward;
}
let actionV = ActionV.nomove;
if (up) {
actionV = ActionV.up;
} else if (down) {
actionV = ActionV.down;
}
let actionS = ActionS.nomove;
if (this.shoot) {
actionS = ActionS.shoot;
}
this.player.applyActionHVS(actionH, actionV, actionS);
this.pastShoot = shoot;
/*
if (shoot) {
if (up) {
if (left) {
this.player.applyAction(Action.upleftshoot);
} else if (right) {
this.player.applyAction(Action.uprightshoot);
} else {
this.player.applyAction(Action.upshoot);
}
} else if (down) {
if (left) {
this.player.applyAction(Action.downleftshoot);
} else if (right) {
this.player.applyAction(Action.downrightshoot);
} else {
this.player.applyAction(Action.downshoot);
}
} else {
if (left) {
this.player.applyAction(Action.leftshoot);
} else if (right) {
this.player.applyAction(Action.rightshoot);
} else {
this.player.applyAction(Action.nomoveshoot);
}
}
} else {
if (up) {
if (left) {
this.player.applyAction(Action.upleft);
} else if (right) {
this.player.applyAction(Action.upright);
} else {
this.player.applyAction(Action.up);
}
} else if (down) {
if (left) {
this.player.applyAction(Action.downleft);
} else if (right) {
this.player.applyAction(Action.downright);
} else {
this.player.applyAction(Action.down);
}
} else {
if (left) {
this.player.applyAction(Action.left);
} else if (right) {
this.player.applyAction(Action.right);
} else {
this.player.applyAction(Action.nomove);
}
}
}
*/
}
}