-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tank.java
197 lines (175 loc) · 5.61 KB
/
Tank.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
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
package team079;
import team079.util.ComSystem;
import battlecode.common.*;
public class Tank extends BaseRobot {
public RobotController rc;
public MapLocation lastWaypoint;
public MapLocation currentWaypoint;
public boolean beWimp;
public boolean notDed;
public Tank(RobotController rcin){
super(rcin);
rc = rcin;
notDed = true;
currentWaypoint =ourHQ;
lastWaypoint = ourHQ;
beWimp = true;
}
@Override
public void run() throws GameActionException {
if(rc.getLocation().distanceSquaredTo(currentWaypoint) <= 2){
ComSystem.incSync(57575);
}
/*if(rc.getHealth() <20 && notDed){
//we ded
rc.broadcast(21, rc.readBroadcast(21)+1);
notDed = false;
}*/
if(rc.getLocation().distanceSquaredTo(currentWaypoint) < 40 && robotsOnTeam(RobotType.TANK, 80, rc.getTeam()).length < 8){
rc.broadcast(21, 200);
}
updateWaypoint();
warMonger();
rc.yield();
}
private void updateWaypoint() throws GameActionException {
if(!currentWaypoint.equals(ComSystem.getLocation(199))){
lastWaypoint = currentWaypoint;
currentWaypoint = ComSystem.getLocation(199);
beWimp = true;
//rc.broadcast(59059, 0);
}
}
private void warMonger() throws GameActionException {
/*beWimp = (!beWimp)? beWimp:robotsOnTeam(RobotType.TANK, 500, rc.getTeam()).length < 20;
if(!beWimp){
rc.broadcast(59059, 1);
}
beWimp = rc.readBroadcast(59059) == 0;*/
int total = 0;
RobotInfo[] bots = rc.senseNearbyRobots(currentWaypoint, 50, rc.getTeam());
for(RobotInfo bot: bots){
if(bot.type == RobotType.TANK){
total++;
}
}
beWimp = total < 10 && Clock.getRoundNum() < rc.getRoundLimit()-400;
dartAway(); //detectAvoidDanger();
destroy();
supplyChain();
basicPathingSwarm(rc.getLocation().directionTo(currentWaypoint));
}
private int howManyFriendsIsSafe() throws GameActionException{
if(rc.canSenseLocation(currentWaypoint)){
RobotInfo target = rc.senseRobotAtLocation(currentWaypoint);
if(target != null){
return (int) (13*target.health/target.type.maxHealth);
}
}
return 10;
}
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.TANK){
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;
}
}
}
}
@Override
public void destroy() throws GameActionException {
RobotInfo[] enemies = rc.senseNearbyRobots(40, rc.getTeam().opponent());
RobotInfo toDestroy = null;
int lowestHealth =100000;
int lowestID = 1000000;
for(RobotInfo enemy : enemies){
if(enemy.type == RobotType.TOWER){
toDestroy = enemy;
break;
}
if(enemy.type == RobotType.HQ){
toDestroy = enemy;
break;
}
boolean beatsBest = (enemy.health < lowestHealth)? true: enemy.ID < lowestID;
if(beatsBest){
lowestHealth = (int) enemy.health;
lowestID = enemy.ID;
toDestroy = enemy;
}
}
if(toDestroy != null)
if(rc.isWeaponReady()&&rc.canAttackLocation(toDestroy.location)){
rc.attackLocation(toDestroy.location);
}
}
private void detectAvoidDanger() throws GameActionException {
Direction dangerWillRobinson = locateTheDanger(false);
if(dangerWillRobinson != null){
basicPathing(dangerWillRobinson);
}
}
private void dartAway() throws GameActionException {
if(!beWimp ) return;
RobotInfo[] Robots = rc.senseNearbyRobots(30, rc.getTeam().opponent());
for(RobotInfo ri: Robots){
if(rc.getLocation().distanceSquaredTo(ri.location) <= ri.type.attackRadiusSquared){
basicPathingSafe(ri.location.directionTo(rc.getLocation()));
}
}
}
public boolean basicPathingSwarm(Direction toMove) throws GameActionException{
//If we are close enough to the waypoint, don't even bother moving
if(rc.getLocation().distanceSquaredTo(currentWaypoint) <= 2) return false;
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;
}
for(MapLocation loc: rc.senseEnemyTowerLocations()){
if(wouldMoveTo.distanceSquaredTo(loc) <= 24 && beWimp){//RobotType.TOWER.attackRadiusSquared){
badLoc = true;
}
}
if(wouldMoveTo.distanceSquaredTo(rc.senseEnemyHQLocation()) <= 24 && beWimp){//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;
}
}