-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRobotPlayer.java
More file actions
230 lines (205 loc) · 7.28 KB
/
RobotPlayer.java
File metadata and controls
230 lines (205 loc) · 7.28 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
package team037;
import battlecode.common.*;
import battlecode.common.Clock;
import battlecode.common.MapLocation;
import battlecode.common.RobotController;
import battlecode.common.RobotType;
import team037.Enums.Bots;
import team037.Enums.Strategies;
import team037.Units.AlphaArchon;
import team037.Units.BaseUnits.*;
import team037.Units.CastleUnits.CastleArchon;
import team037.Units.Scavenger.ScavengerArchon;
import team037.Units.ScoutBomb.ScoutBombArchon;
import team037.Units.SuperRush.SuperRushArchon;
import team037.Units.TurtleUnits.TurtleArchon;
public class RobotPlayer
{
private static Unit unit;
public static String strategy;
/**
* run() is the method that is called when a robot is instantiated in the Battlecode world.
* If this method returns, the robot dies!
**/
public static void run(RobotController rc)
{
try
{
// this will check your ./bc.conf file for a line like this:
// bc.testing.strat=foo
// and strategy will be foo
strategy = System.getProperty("bc.testing.strat");
// IT DOESN'T WORK CURRENTLY :(
// BUT THEY ARE FIXING IT!
// hardcode disabled for now
strategy = Strategies.VIPERS;
/*MapLocation[] us = rc.getInitialArchonLocations(rc.getTeam());
MapLocation[] them = rc.getInitialArchonLocations(rc.getTeam().opponent());
ZombieTracker zombieTracker = new ZombieTracker(rc);
int[] size = StrategyUtilities.estimatedSize(us, them);
int[] schedule = rc.getZombieSpawnSchedule().getRounds();
if (((StrategyUtilities.averageDistToEnemyArchons(us, them) > 100) &&
size[0] * size[1] > 400 &&
!StrategyUtilities.enemyBetweenBuddies(us, them) &&
schedule[0] < 300 &&
zombieTracker.getZombieStrength() >= 2))
{
strategy = Strategies.TURTLE;
}
else
{
strategy = Strategies.RUSH;
}*/
if(rc.getRoundNum() == 0)
{
System.out.println(strategy);
}
RobotType type = rc.getType();
//TODO: archon switch for round > 1 to differentite activated archons
if(type == RobotType.ARCHON)
{
if(rc.getRoundNum() == 0)
{
if(shouldRush(rc.getInitialArchonLocations(rc.getTeam().opponent()),
rc.getInitialArchonLocations(rc.getTeam()), rc.getLocation(), rc))
{
strategy = Strategies.RUSH;
}
}
if(strategy.equals(Strategies.CASTLE))
{
unit = new CastleArchon(rc);
}
else if(strategy.equals(Strategies.TURTLE))
{
unit = new TurtleArchon(rc);
Unit.thisBot = Bots.TURTLEARCHON;
}
else if(strategy.equals(Strategies.SCOUT_BOMB))
{
unit = new ScoutBombArchon(rc);
Unit.thisBot = Bots.SCOUTBOMBARCHON;
}
else if(strategy.equals(Strategies.PACMAN))
{
unit = new ScavengerArchon(rc);
Unit.thisBot = Bots.SCAVENGERARCHON;
}
else if(strategy.equals(Strategies.RUSH))
{
unit = new SuperRushArchon(rc);
Unit.thisBot = Bots.SUPERRUSHARCHON;
}
else
{
// default to alpha archons
unit = new AlphaArchon(rc);
Unit.thisBot = Bots.ALPHAARCHON;
}
}
else if(type == RobotType.GUARD)
{
unit = new BaseGaurd(rc);
Unit.thisBot = Bots.BASEGAURD;
}
else if(type == RobotType.SCOUT)
{
unit = new BaseScout(rc);
Unit.thisBot = Bots.BASESCOUT;
}
else if(type == RobotType.SOLDIER)
{
unit = new BaseSoldier(rc);
Unit.thisBot = Bots.BASESOLDIER;
}
else if(type == RobotType.TURRET || type == RobotType.TTM)
{
unit = new BaseTurret(rc);
Unit.thisBot = Bots.BASETURRET;
}
else if(type == RobotType.VIPER)
{
unit = new BaseViper(rc);
Unit.thisBot = Bots.BASEVIPER;
}
// initial update to strategy
try
{
unit = unit.getNewStrategy(unit);
}
catch(Exception e)
{
e.printStackTrace();
}
}
catch(Exception e){e.printStackTrace();}
// Game loop that will execute very round
while (true)
{
Unit.msgsSent = 0;
try
{
unit.collectData();
unit.handleMessages();
unit.sendMessages();
// default is fight, fightZombie, carryOutAbility, takeNextStep
unit.act();
unit = unit.getNewStrategy(unit);
unit.suicide();
}
catch (Exception e)
{
e.printStackTrace();
}
Clock.yield();
}
}
private static boolean shouldRush(MapLocation[] enemyArchonStartLocs, MapLocation[] alliedArchonStartLocs,
MapLocation currentLocation, RobotController rc)
{
int[] archons = new int[enemyArchonStartLocs.length];
RobotInfo[] neutrals = rc.senseNearbyRobots(RobotType.ARCHON.sensorRadiusSquared, Team.NEUTRAL);
int minus = neutrals.length * 20;
for(int k = archons.length; --k >= 0;)
{
archons[k] -= minus;
int dist = currentLocation.distanceSquaredTo(enemyArchonStartLocs[k]);
archons[k] += dist;
for(int a = alliedArchonStartLocs.length; --a >= 0;)
{
if(!alliedArchonStartLocs[a].equals(currentLocation))
{
if(alliedArchonStartLocs[a].distanceSquaredTo(enemyArchonStartLocs[k]) <= dist)
{
archons[k] += dist;
}
}
}
MapLocation current = currentLocation;
while(rc.canSenseLocation(current) && !current.equals(enemyArchonStartLocs[k]))
{
double rubble = rc.senseRubble(current);
if(rubble >= 100)
{
archons[k] += 1000;
}
current = current.add(current.directionTo(enemyArchonStartLocs[k]));
}
}
int index = 0;
int min = 9999999;
for(int k = archons.length; --k >= 0;)
{
if(archons[k] < min)
{
min = archons[k];
index = k;
}
}
if(min <= 100)
{
return true;
}
return false;
}
}