-
Notifications
You must be signed in to change notification settings - Fork 5
/
Unit.java
36 lines (29 loc) · 902 Bytes
/
Unit.java
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
package lectureplayer;
import battlecode.common.*;
public class Unit extends Robot {
Navigation nav;
MapLocation hqLoc;
public Unit(RobotController r) {
super(r);
nav = new Navigation(rc);
}
public void takeTurn() throws GameActionException {
super.takeTurn();
findHQ();
}
public void findHQ() throws GameActionException {
if (hqLoc == null) {
// search surroundings for HQ
RobotInfo[] robots = rc.senseNearbyRobots();
for (RobotInfo robot : robots) {
if (robot.type == RobotType.HQ && robot.team == rc.getTeam()) {
hqLoc = robot.location;
}
}
if(hqLoc == null) {
// if still null, search the blockchain
hqLoc = comms.getHqLocFromBlockchain();
}
}
}
}