-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSoldier.java
165 lines (149 loc) · 3.38 KB
/
Soldier.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
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
package team022;
import battlecode.common.*;
public class Soldier extends BaseRobot {
public MapLocation den;
public MapLocation initialLocation;
public GuardState state = GuardState.DEFENDING;
public Soldier(RobotController rcin) {
super(rcin);
}
public enum GuardState{
DEFENDING, ATTACKING, RETURNING;
}
@Override
public void run() {
switch(lifePlan){
case MONGOLS:
mongolian();
break;
case TURRTLE:
turtle();
break;
}
}
public void turtle(){
while(true){
boolean neededToMove = false;
iNeedMySpaceMom();
if(!neededToMove){
rc.setIndicatorString(0, "In Position, TIME TO KILL!!!");
defense();
}
try {
springCleaning();
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Clock.yield();
}
}
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;
}
iNeedMySpaceMom();
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;
}
public MapLocation findArchon(){
for( RobotInfo bot: rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam())){
if(bot.type == RobotType.ARCHON){
return bot.location;
}
}
return null;
}
public void iNeedMySpaceMom(){
MapLocation mommy = findArchon();
if(mommy != null){
if(rc.getLocation().distanceSquaredTo(mommy) < 10){
if(rand.nextDouble() < 0.4){
try {
moveAsCloseToDirection(mommy.directionTo(rc.getLocation()), false);
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
}
}