forked from andrepl/bcode2013
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArtilleryBot.java
More file actions
42 lines (35 loc) · 1.36 KB
/
ArtilleryBot.java
File metadata and controls
42 lines (35 loc) · 1.36 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
package team028;
import battlecode.common.*;
public class ArtilleryBot extends Bot {
public ArtilleryBot(Robot robot, int robotId, Team team, RobotType robotType, RobotController rc) {
super(robot, robotId, team, robotType, rc);
}
public void go() throws GameActionException {
super.go();
if (rc.isActive()) {
Robot[] nearby = rc.senseNearbyGameObjects(Robot.class, myLocation, RobotType.ARTILLERY.attackRadiusMaxSquared, opponentTeam);
Robot[] tooNearby = rc.senseNearbyGameObjects(Robot.class, myLocation, RobotType.ARTILLERY.attackRadiusMinSquared, opponentTeam);
MapLocation nearest = null;
for (Robot r: nearby) {
if (robotArrayContains(tooNearby, r.getID())) {
continue;
}
MapLocation loc = rc.senseLocationOf(r);
if (nearest == null || loc.distanceSquaredTo(myHqLocation) < nearest.distanceSquaredTo(myHqLocation)) {
nearest = loc;
}
}
if (nearest != null) {
rc.attackSquare(nearest);
}
}
}
public boolean robotArrayContains(Robot[] arr, int robotId) {
for (Robot r: arr) {
if (r.getID() == robotId) {
return true;
}
}
return false;
}
}