-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLauncher.java
More file actions
279 lines (253 loc) · 8.44 KB
/
Launcher.java
File metadata and controls
279 lines (253 loc) · 8.44 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
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
package team079;
import team079.util.ComSystem;
import battlecode.common.*;
public class Launcher extends BaseRobot {
public RobotController rc;
public MapLocation lastWaypoint;
public MapLocation currentWaypoint;
public Direction dangerWillRobinson;
//public int myID;
public Launcher(RobotController rcin){
super(rcin);
rc = rcin;
initBetterPathing(ourHQ);
currentWaypoint =ourHQ;
lastWaypoint = ourHQ;
//int myID = robotsOfTypeOnTeam(RobotType.LAUNCHER, rc.getTeam());
}
@Override
public void run() throws GameActionException {
detectAvoidDanger();
rc.setIndicatorString(0,"Going to " +ComSystem.getLocation(199));
//ComSystem.sendLocation(myID+200,rc.getLocation(), true);
if(rc.isWeaponReady() && rc.getMissileCount() >=1){
//ComSystem.incSync(57575);
}
//launchAtWeakest();
//dartAway();
updateWaypoint();
swarmMoving();
supplyChain();
//basicPathingSwarm(rc.getLocation().directionTo(ComSystem.getLocation(199)));
rc.yield();
}
private void detectAvoidDanger() throws GameActionException {
dangerWillRobinson = locateTheDanger(true);
if(dangerWillRobinson != null){
basicPathing(dangerWillRobinson);
}
}
private void updateWaypoint() throws GameActionException {
if(!currentWaypoint.equals(ComSystem.getLocation(199))){
lastWaypoint = currentWaypoint;
currentWaypoint = ComSystem.getLocation(199);
}
}
private void supplyChain() throws GameActionException{
RobotInfo[] Robots = rc.senseNearbyRobots(15, rc.getTeam());
for(RobotInfo ri: Robots){
if(ri.supplyLevel<rc.getSupplyLevel()*0.75){
int toSupply = 0;
if(ri.type == RobotType.LAUNCHER){
toSupply = (int) ((rc.getSupplyLevel()-ri.supplyLevel)/2);
}
if(ri.type == RobotType.SOLDIER){
toSupply = (int) ((rc.getSupplyLevel() - ri.supplyLevel)/4);
}
if(rc.senseRobotAtLocation(ri.location) != null && toSupply !=0){
rc.transferSupplies(toSupply, ri.location);
break;
}
}
}
}
public void launchAtWeakest() throws GameActionException{
//if(ComSystem.readSync(57575) < 10) return;
RobotInfo[] enemiesInRange = rc.senseNearbyRobots(25, rc.getTeam().opponent());
double LowestHealth = 10000;
RobotInfo weakestLink = null;
for(RobotInfo ri:enemiesInRange){
if(ri.type == RobotType.TOWER){
weakestLink = ri;
break;
}
if(ri.type == RobotType.HQ){
weakestLink = ri;
break;
}
if(ri.health<LowestHealth && clearPath(rc.getLocation(), ri.location)){
weakestLink = ri;
LowestHealth = ri.health;
}
}
if(weakestLink != null){
Direction dir = rc.getLocation().directionTo(weakestLink.location);
Direction[] toTry = {dir, dir.rotateLeft(), dir.rotateRight(), dir.rotateLeft().rotateLeft(), dir.rotateRight().rotateRight()};
int launched = 0;
for(Direction launch:toTry){
if(rc.isWeaponReady()&&rc.canLaunch(launch)&&rc.getMissileCount()>=1){
rc.launchMissile(launch);
launched ++;
if(launched >3 && weakestLink.type != RobotType.TOWER && weakestLink.type != RobotType.HQ ){
break;
}
}
}
}
}
public void launchAnyways() throws GameActionException{
Direction dir = rc.getLocation().directionTo(ComSystem.getLocation(199));
Direction[] toTry = {dir, dir.rotateLeft(), dir.rotateRight(), dir.rotateLeft().rotateLeft(), dir.rotateRight().rotateRight()};
for(Direction launch:toTry){
if(rc.isWeaponReady()&&rc.canLaunch(launch)&&rc.getMissileCount()>=1){
rc.launchMissile(launch);
break;
}
}
}
public boolean shouldWeMove() throws GameActionException{
MapLocation[] towers = rc.senseEnemyTowerLocations();
MapLocation wouldMoveTo = rc.getLocation().add(rc.getLocation().directionTo(ComSystem.getLocation(199)));
if(rc.getLocation().distanceSquaredTo(ComSystem.getLocation(199)) < 4){
return false;
}
for(MapLocation loc: towers){
if(wouldMoveTo.distanceSquaredTo(loc) <= 20){//RobotType.TOWER.attackRadiusSquared){
return false;
}
}
if(wouldMoveTo.distanceSquaredTo(rc.senseEnemyHQLocation()) <= 16){//RobotType.HQ.attackRadiusSquared){
return false;
}
RobotInfo[] robots = rc.senseNearbyRobots(wouldMoveTo, 20, rc.getTeam().opponent());
if(robots.length == 0){
return true;
}else{
return false;
}
}
public boolean shouldWeMove(MapLocation target) throws GameActionException{
MapLocation[] towers = rc.senseEnemyTowerLocations();
MapLocation wouldMoveTo = rc.getLocation().add(rc.getLocation().directionTo(target));
for(MapLocation loc: towers){
if(wouldMoveTo.distanceSquaredTo(loc) <= 20){//RobotType.TOWER.attackRadiusSquared){
return false;
}
}
if(wouldMoveTo.distanceSquaredTo(rc.senseEnemyHQLocation()) <= 16){//RobotType.HQ.attackRadiusSquared){
return false;
}
RobotInfo[] robots = rc.senseNearbyRobots(wouldMoveTo, 40, rc.getTeam().opponent());
for(RobotInfo robot: robots){
if(rc.getLocation().distanceSquaredTo(robot.location) < robot.type.attackRadiusSquared){
return false;
}
}
return true;
}
private void dartAway() throws GameActionException {
RobotInfo[] Robots = rc.senseNearbyRobots(30, rc.getTeam().opponent());
for(RobotInfo ri: Robots){
if(rc.getLocation().distanceSquaredTo(ri.location) <= ri.type.attackRadiusSquared){
moveAsCloseToDirection(ri.location.directionTo(rc.getLocation()));
}
}
}
public boolean swarmMoving() throws GameActionException{
/*
RobotInfo[] swarmMates = robotsOnTeam(RobotType.LAUNCHER, 40, rc.getTeam());
int sumLocx = 0;
int sumLocy = 0;
int sumInRange = 0;
int total = 0;
for(RobotInfo ri: swarmMates){
if(ri == null) break;
sumInRange++;
sumLocx+=ri.location.x;
sumLocy+=ri.location.y;
total++;
}
if(total == 0){
sumLocx = rc.getLocation().x;
sumLocy = rc.getLocation().y;
total = 1;
}
MapLocation center = new MapLocation(sumLocx/total, sumLocy/total);
MapLocation target;
if(rc.getMissileCount() >2){
target = center.add(center.directionTo(currentWaypoint),4);
}else{
target = center.add(center.directionTo(currentWaypoint).opposite(), 4);
}*/
MapLocation target;
if(rc.getMissileCount() >2){
target = currentWaypoint;
}else{
target = currentWaypoint.add(currentWaypoint.directionTo(lastWaypoint), 4);
}
/*
if(target.distanceSquaredTo(rc.getLocation()) > currentWaypoint.distanceSquaredTo(rc.getLocation())){
target = currentWaypoint;
}
*/
if(!shouldWeMove(target) || rc.getMissileCount() >2){
launchAtWeakest();
return false;
}else if(shouldWeMove(target)){
return basicPathingSwarm(rc.getLocation().directionTo(target));
}else{
return false;
}
}
public boolean basicPathingSwarm(Direction toMove) throws GameActionException{
if(rc.isCoreReady()){
oldLocs.remove(0);
while(oldLocs.size() < NUMOLDLOCS){
oldLocs.add(new MapLocation(0,0));
}
Direction[] toTry = {toMove,
toMove.rotateLeft(),
toMove.rotateRight(),
toMove.rotateLeft().rotateLeft(),
toMove.rotateRight().rotateRight(),
toMove.rotateLeft().rotateLeft().rotateLeft(),
toMove.rotateRight().rotateRight().rotateRight(),
toMove.rotateLeft().rotateLeft().rotateLeft().rotateLeft()
};
for(Direction dir:toTry){
boolean badLoc = false;
MapLocation wouldMoveTo = rc.getLocation().add(dir);
if(oldLocs.contains(rc.getLocation().add(dir))){
badLoc = true;
}
RobotInfo[] launches = robotsOnTeam(RobotType.LAUNCHER, 10, rc.getTeam());
for(RobotInfo launcher:launches){
if(rc.getLocation().add(dir).distanceSquaredTo(launcher.location) <2){
//badLoc = true;
}
}
for(MapLocation loc: rc.senseEnemyTowerLocations()){
if(wouldMoveTo.distanceSquaredTo(loc) <= 20){//RobotType.TOWER.attackRadiusSquared){
badLoc = true;
}
}
if(wouldMoveTo.distanceSquaredTo(rc.senseEnemyHQLocation()) <= 20){//RobotType.HQ.attackRadiusSquared){
badLoc = true;
}
rc.setIndicatorString(2, badLoc +"");
if(rc.canMove(dir)&&rc.isCoreReady() && !badLoc){
rc.setIndicatorString(1, dir.toString() + ", " + Clock.getRoundNum());
oldLocs.add(rc.getLocation().add(dir));
lastDir = dir;
lastTried = toMove;
rc.move(dir);
return true;
}
}
}
return false;
}
public MapLocation[] findFrontLine(){
return null;
}
}