-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBarracks.java
More file actions
50 lines (42 loc) · 1.31 KB
/
Barracks.java
File metadata and controls
50 lines (42 loc) · 1.31 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
package team079;
import team079.util.ComSystem;
import battlecode.common.*;
public class Barracks extends BaseRobot {
public RobotController rc;
public boolean towerDefense;
public Barracks(RobotController rcin){
super(rcin);
rc = rcin;
towerDefense = false;
for(MapLocation loc: rc.senseTowerLocations()){
if(rc.getLocation().isAdjacentTo(loc)){
towerDefense = true;
}
}
}
@Override
public void run() throws GameActionException {
if(towerDefense){
towerDefense();
}else{
opsAsNormal();
}
rc.yield();
}
public void opsAsNormal() throws GameActionException{
if(robotsOfTypeOnTeam(RobotType.SOLDIER, rc.getTeam()) < 10 || robotsOfTypeOnTeam(RobotType.TANK, rc.getTeam()) >40 )
spawnUnit(RobotType.SOLDIER);
}
public void towerDefense() throws GameActionException{
int limit = (rc.senseNearbyRobots(40, rc.getTeam().opponent()).length > 0)? 16:6;
if(robotsOnTeam(RobotType.BASHER, 40, rc.getTeam()).length + robotsOnTeam(RobotType.SOLDIER, 40, rc.getTeam()).length < limit){
if(robotsOnTeam(RobotType.SOLDIER, rc.getTeam()).length + robotsOnTeam(RobotType.BASHER, rc.getTeam()).length < 30){
if(rand.nextDouble() < 0.1){
spawnUnit(RobotType.BASHER);
}else{
spawnUnit(RobotType.SOLDIER);
}
}
}
}
}