-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDrone.java
More file actions
189 lines (154 loc) · 4.51 KB
/
Drone.java
File metadata and controls
189 lines (154 loc) · 4.51 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
package team079;
import team079.util.ComSystem;
import battlecode.common.*;
public class Drone extends BaseRobot {
public RobotController rc;
public boolean supplying;
public boolean areWeAnnoying;
public boolean areWeMeanderer;
public MapLocation center;
public enum ID{
SCOUTING,FIND_WAYPOINT,
SUPPLY_MINERS,SUPPLY_TANKS,
HARASS
}
public ID myID;
public Drone(RobotController rcin){
super(rcin);
rc = rcin;
supplying = false;
myID = ID.SCOUTING;
try {
rc.broadcast(2099, rc.readBroadcast(2099)+1);
areWeAnnoying = rc.readBroadcast(2099) <15;
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
areWeAnnoying =false;
try {
rc.broadcast(2990, rc.readBroadcast(2990)+1);
areWeMeanderer = rc.readBroadcast(2990) <=1;
} catch (GameActionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
center = new MapLocation(0,0);
}
@Override
public void run() throws GameActionException {
rc.setIndicatorString(0, ""+ myID);
ComSystem.handleDroneID(myID);
switch(myID){
case SCOUTING:
scoutMap();
break;
case FIND_WAYPOINT:
findWaypoint();
break;
case SUPPLY_MINERS:
supplyMiners();
break;
case SUPPLY_TANKS:
supplyTheTanks();
break;
case HARASS:
harass();
break;
}
rc.yield();
}
private void harass() {
// TODO Auto-generated method stub
}
private void supplyTheTanks() throws GameActionException {
RobotInfo[] tanks = robotsOnTeam(RobotType.TANK, rc.getTeam());
if(supplying){
RobotInfo closestToWaypoint = null;
int bestDisToWaypoint = 1000000;
for(RobotInfo ri: tanks){
if(ri.supplyLevel < 3000 && rc.getLocation().distanceSquaredTo(ri.location) < bestDisToWaypoint){
closestToWaypoint = ri;
bestDisToWaypoint = rc.getLocation().distanceSquaredTo(ri.location);
break;
}
}
if(closestToWaypoint != null){
basicPathingSafe(rc.getLocation().directionTo(closestToWaypoint.location));
}
if(rc.getLocation().distanceSquaredTo(ComSystem.getLocation(199)) < 60){
for(RobotInfo ri: tanks){
int toSupply = 0;
//if(rc.getLocation().distanceSquaredTo(ComSystem.getLocation(199)) < 50)
toSupply = Math.max((int) rc.getSupplyLevel() - 150,0);
/*else if(ri.supplyLevel < 2000)
toSupply = (int) Math.min(2000, rc.getSupplyLevel()/2);*/
if(rc.senseRobotAtLocation(ri.location) != null){
if(rc.senseRobotAtLocation(ri.location).team == rc.getTeam()){
if(ri.location.distanceSquaredTo(rc.getLocation())< 15){
rc.transferSupplies(toSupply, ri.location);
break;
}
}
}
}
}
if(rc.getSupplyLevel() < 1000){
supplying = false;
}
}else{
basicPathingSafe(rc.getLocation().directionTo(rc.senseHQLocation()));
if(rc.getSupplyLevel() > 5000){
supplying = true;
}
}
//if(rc.getSupplyLevel() < -)
}
private void findWaypoint() {
// TODO Auto-generated method stub
}
@SuppressWarnings("unused")
private void scoutMap() throws GameActionException {
if(false) //if(ComSytem.pathingDone() && numOfDronesOfType(ID.FIND_WAYPOINT) < 1)
{
myID = ID.FIND_WAYPOINT;
}
if(ComSystem.numOfDronesOfType(ID.SCOUTING) >-1000){
myID = ID.SUPPLY_MINERS;
}
}
private void supplyMiners() throws GameActionException {
RobotInfo[] miners = robotsOnTeam(RobotType.MINER, rc.getTeam());
if(supplying){
for(RobotInfo ri: miners){
int toSupply = 0;
toSupply = Math.max((int) rc.getSupplyLevel() - 150,0)/20;
if(rc.senseRobotAtLocation(ri.location) != null){
if(rc.senseRobotAtLocation(ri.location).team == rc.getTeam()){
if(ri.location.distanceSquaredTo(rc.getLocation())< 15){
rc.transferSupplies(toSupply, ri.location);
break;
}
}
}
if(ri.supplyLevel < 50){
basicPathingSafe(rc.getLocation().directionTo(ri.location));
break;
}
}
if(rc.getSupplyLevel() < 250){
supplying = false;
}
}else{
basicPathingSafe(rc.getLocation().directionTo(rc.senseHQLocation()));
if(rc.getSupplyLevel() > 1000){
supplying = true;
}
}
if( ComSystem.numOfDronesOfType(ID.SUPPLY_TANKS) <4 || robotsOfTypeOnTeam(RobotType.TANK, rc.getTeam()) >8){
myID = ID.SUPPLY_TANKS;
ComSystem.handleDroneID(myID);
System.out.println(ComSystem.numOfDronesOfType(ID.SUPPLY_TANKS));
}
}
}