-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGuard.java
129 lines (115 loc) · 2.52 KB
/
Guard.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
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
package team022;
import battlecode.common.*;
public class Guard extends BaseRobot {
MapLocation initialLocation;
GuardState state = GuardState.DEFENDING;
MapLocation den;
public enum GuardState{
DEFENDING, ATTACKING, RETURNING;
}
public Guard(RobotController rcin) {
super(rcin);
// TODO Auto-generated constructor stub
initialLocation = rc.getLocation();
}
@Override
public void run() {
switch(lifePlan){
case MONGOLS:
mongolian();
break;
case TURRTLE:
turtle();
break;
}
}
public void turtle(){
while(true){
defense();
}
}
public void mongolian(){
while(true){
switch(state){
case DEFENDING:
recieveTargets();
MapLocation target = closestTarget();
if(target != null){
den = target;
state = GuardState.ATTACKING;
initialLocation = rc.getLocation();
break;
}
if(rc.isCoreReady() && rand.nextDouble() < 0.5){
try {
springCleaning();
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
defense();
if(rc.isCoreReady()){
try {
springCleaning();
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Clock.yield();
break;
case ATTACKING:
rc.setIndicatorString(2, den.toString());
try {
if(denGone()){
state = GuardState.RETURNING;
destroyedTargets.add(den);
targets.remove(den);
break;
}
} catch (GameActionException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if(rc.isCoreReady() && rand.nextDouble() < 0.5){
try {
springCleaning();
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
attack(den);
Clock.yield();
break;
case RETURNING:
RobotInfo[] ourBots = rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam());
boolean archon = false;
for(RobotInfo bot : ourBots){
if(bot.type == RobotType.ARCHON){
archon = true;
}
}
if(archon){
state = GuardState.DEFENDING;
break;
}else{
slugPathing(initialLocation);
Clock.yield();
}
break;
}
rc.setIndicatorString(0, state.toString());
}
}
private boolean denGone() throws GameActionException {
if(rc.canSense(den)){
RobotInfo checker = rc.senseRobotAtLocation(den);
if(checker == null || checker.type != RobotType.ZOMBIEDEN){
return true;
}
}
return false;
}
}