-
Notifications
You must be signed in to change notification settings - Fork 0
/
Basher.java
65 lines (56 loc) · 1.62 KB
/
Basher.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
package team079;
import battlecode.common.*;
public class Basher extends BaseRobot {
public RobotController rc;
public MapLocation tower;
public Basher(RobotController rcin){
super(rcin);
rc = rcin;
int lowestDistance = 1000000;
tower = null;
for(MapLocation loc: rc.senseTowerLocations()){
if(rc.getLocation().distanceSquaredTo(loc) < lowestDistance){
lowestDistance = rc.getLocation().distanceSquaredTo(loc);
tower = loc;
}
}
System.out.println(rc.getLocation());
rc.yield();
}
@Override
public void run() throws GameActionException {
bullRush();
bullPen();
}
private void bullRush() throws GameActionException {
int smallestDistance = 100000;
RobotInfo redCape = null;
for(RobotInfo enemy:rc.senseNearbyRobots(rc.getType().sensorRadiusSquared, rc.getTeam().opponent())){
if(enemy.type != RobotType.MISSILE){
if(smallestDistance > enemy.location.distanceSquaredTo(rc.getLocation())){
redCape = enemy;
smallestDistance = enemy.location.distanceSquaredTo(rc.getLocation());
}
}
}
if(redCape != null){
moveAsCloseToDirection(rc.getLocation().directionTo(redCape.location));
}
}
private void bullPen() throws GameActionException{
Direction toMove = rc.getLocation().directionTo(tower);
if(rc.isCoreReady()){
Direction[] toTry = {toMove,
toMove.rotateLeft(),
toMove.rotateRight(),
toMove.rotateLeft().rotateLeft(),
toMove.rotateRight().rotateRight()
};
for(Direction dir:toTry){
if(rc.canMove(dir)&&rc.isCoreReady()){
rc.move(dir);
}
}
}
}
}