-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathPlayer.php
More file actions
175 lines (138 loc) · 2.61 KB
/
Player.php
File metadata and controls
175 lines (138 loc) · 2.61 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
<?php
/**
* Defines the point object
*/
class Point {
/**
* X position on the map
* @var int
*/
public $x = 0;
/**
* Y position on the map
* @var int
*/
public $y = 0;
public function __toString() {
return sprintf('%d %d', $this->x, $this->y);
}
}
/**
* Drone object referring the position on the map
*/
class Drone {
/**
* Position of the drone
* @var Point
*/
public $pos;
public function __construct() {
$this->pos = new Point();
}
}
/**
* Zone object referencing the position on the map
*/
class Zone {
/**
* The center of the zone
* (circle radius = 100 units)
* @var Point
*/
public $center;
/**
* The owner ID
* @var int
*/
public $ownerId = -1;
public function __construct() {
$this->center = new Point();
}
}
/**
* Team object referencing their drones
*/
class Team {
/**
* List of drones
* @var array
*/
public $drones = array();
}
/**
* Game logic
*/
class Game {
/**
* List of zones
* @var array
*/
public $zones = array();
/**
* List of teams
* @var array
*/
public $teams = array();
/**
* My team ID
* @var int
*/
public $myTeamId = -1;
/**
* Read initialization data from standard input
*/
public function init() {
// p = number of players in the game 2 to 4
// i = id of your player(0,1,2 or 3)
// d = number of drones in each team(3 to 11)
// z = number of zones in map(4 to 8)
list($p, $i, $d, $z) = explode(' ', trim(fgets(STDIN)), 4);
// Set my team id
$this->myTeamId = $i;
// Each zone
for ($areaId = 0; $areaId < $z; $areaId++) {
$z1 = new Zone();
list($z1->center->x, $z1->center->y) = explode(' ', trim(fgets(STDIN)), 2);
$this->zones[$areaId] = $z1;
}
// Each team
for ($teamId = 0; $teamId < $p; $teamId++) {
$t1 = new Team();
// Add the drones to the team
for ($droneId = 0; $droneId < $d; $droneId++) {
$t1->drones[$droneId] = new Drone();
}
$this->teams[$teamId] = $t1;
}
}
/**
* Called during each round
* reads input datas (zone ownerid and the coordinates of drones of all teams)
*/
public function run() {
while (1) {
foreach ($this->zones as $zone) {
$zone->ownerId = (int) trim(fgets(STDIN));
}
foreach ($this->teams as $team) {
foreach ($team->drones as $drone) {
list($drone->pos->x, $drone->pos->y) = explode(' ', trim(fgets(STDIN)), 2);
}
}
$this->play();
}
}
/**
* Your logic goes here
*/
public function play() {
$myDrones = $this->teams[$this->myTeamId]->drones;
foreach ($myDrones as $droneId => $drone) {
print "3999 1799\n";
}
}
}
$g = new Game();
$g->init();
$g->run();
?>