-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathai.js
75 lines (61 loc) · 2.2 KB
/
ai.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
/*
Template bot entries
bot1() {
return [dx,dy];
}
dx = number of pixels to move left or right
dy = number of pixels to move up or down
NOTES:
1. The game will normalise these values so the bot moves exactly 1 pixel per turn (or whatever the final speed happens to be)
2. The program will look for bots named bot1, bot2, bot3, bot4 and bot5 ONLY.
3. Any functions you write cannot have 'function' written at the front. This is because all
your code will be encapsulated into a class
4. You may create arrays, variable etc to store things. These should be persistant, that is, exist
between movements of your robots
5. From the game itself you can only access bot information using the game.getPlayerData(playerNumber) function.
This returns an object that looks like this:
class Player {
constructor(x,y,team){
this.x=x; //bot x position
this.y=y; //bot y position
this.team=team; //bot team
this.isInJail = false; //if the bot is captured and in jail
this.distance = 0; //a value that records distance to the flag. This is used for in game stuff like seeing
//if the player is close to the flag. I wouldn't trust it's accuracy as it is only updated
//when the bot is close enough to the flag to pick it up.
}
}
6. You can get the location of the flags using game.getTeamFlag(teamNumber). teamNumber is 0 or 1.
7. You can obtain your own team number by accessing the variable this.team in your code - it is created when you code is encapulated
into a class.
8. All moves by all players are calculated from the game state and applied at the same time. Then collisions/pickups etc are calculated.
*/
bot1(){
let dx=0;
let dy=0;
if (keyIsDown(LEFT_ARROW)){
dx =-1;
}
if (keyIsDown(RIGHT_ARROW)){
dx =1;
}
if (keyIsDown(UP_ARROW)){
dy =-1;
}
if (keyIsDown(DOWN_ARROW)){
dy =1;
}
return [dx, dy];
}
bot2(){
return [1,0];
}
bot3(){
return [1,0];
}
bot4(){
return [1,0];
}
bot5(){
return [1,0];
}