-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPlayer.java
More file actions
80 lines (66 loc) · 1.89 KB
/
Player.java
File metadata and controls
80 lines (66 loc) · 1.89 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
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
import java.util.*;
import java.io.*;
import java.math.*;
import java.awt.Point;
class Player {
Team[] teams; // all the team of drones. Array index = team's ID
int myTeamIdx; // index of my team in the array of teams
Zone[] zones; // all game zones
static class Team {
Point[] drones; // position of the drones
}
static class Zone {
Point pos = new Point(); // center of this zone (circle radius = 100 units)
int owner = -1; // ID of the team which owns this zone, -1 otherwise
}
/**
* Compute logic here. This method is called for each game round.
*/
void play() {
Team me = teams[myTeamIdx];
// here I always ask my drones to reach the bottom right corner... stupid :-)
for (Point drone : me.drones) {
System.out.println("3999 1799");
}
}
// program entry point
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
Player p = new Player();
p.parseInit(in);
while (true) {
p.parseContext(in);
p.play();
}
}
// parse games data (one time at the beginning of the game: P I D Z...)
void parseInit(Scanner in) {
teams = new Team[in.nextInt()]; // P
myTeamIdx = in.nextInt(); // I
int cntDronesPerTeam = in.nextInt(); // D
for (int i = 0; i < teams.length; i++) {
Team t = new Team();
t.drones = new Point[cntDronesPerTeam];
teams[i] = t;
}
zones = new Zone[in.nextInt()]; // Z
for (int i = 0; i < zones.length; i++) {
Zone z = new Zone();
z.pos.x = in.nextInt();
z.pos.y = in.nextInt();
zones[i] = z;
}
}
// parse contextual data to update the game's state (called for each game round)
void parseContext(Scanner in) {
for (Zone z : zones) {
z.owner = in.nextInt(); // update zones owner
}
for (int i = 0; i < teams.length; i++) {
Team t = teams[i];
for (int j = 0; j < t.drones.length; j++) {
t.drones[j] = new Point(in.nextInt(), in.nextInt()); // update drones position
}
}
}
}