-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayerBot.ts
More file actions
47 lines (38 loc) · 1.45 KB
/
playerBot.ts
File metadata and controls
47 lines (38 loc) · 1.45 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
import { Area } from "./sdk/area";
import { RoundContext } from "./sdk/round-context";
import { MoveCollection } from "./sdk/move-collection";
import { BotBase } from "./sdk/bot-base";
export class PlayerBot extends BotBase {
private attack1 = Area.HookKick;
private attack2 = Area.HookPunch;
private defence = Area.HookKick;
private changeDefence(oldDefence: Area): Area
{
return (oldDefence == Area.HookKick) ? Area.HookPunch : Area.HookKick;
}
private createRandomAttack(): Area
{
return Math.random() > 0.5 ? Area.LowKick : Area.HookPunch;
}
public nextMove(context: RoundContext): MoveCollection
{
const myLifePoints = context.getMyLifePoints();
const opponentLifePoints = context.getOpponentLifePoints();
context.getMyMoves()
.addAttack(this.attack1)
.addAttack(this.attack2);
if ((context.getLastOpponentMoves() != null) && context.getLastOpponentMoves().getAttacks().filter(x => x.getArea() == this.defence).length === 0)
{
this.defence = this.changeDefence(this.defence);
}
if (myLifePoints >= opponentLifePoints)
context.getMyMoves().addAttack(this.createRandomAttack()); // 3 attacks, 0 defence
else
context.getMyMoves().addDefence(this.defence);
return context.getMyMoves();
}
public toString(): String
{
return "PlayerBot";
}
}