-
Notifications
You must be signed in to change notification settings - Fork 0
/
Missile.java
85 lines (76 loc) · 2.13 KB
/
Missile.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
package team079;
import team079.util.ComSystem;
import battlecode.common.*;
public class Missile extends BaseRobot {
public Missile(RobotController rcin) {
super(rcin);
// TODO Auto-generated constructor stub
}
public static RobotController rc;
public static int turnsWithoutMoving;
public static void missileInit(RobotController rcin){
rc = rcin;
turnsWithoutMoving = 0;
}
public static void runs() throws GameActionException {
// TODO Auto-generated method stub
explodeWeakest();
rc.yield();
}
public static void explodeWeakest() throws GameActionException{
RobotInfo[] enemiesInRange = rc.senseNearbyRobots(36, 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){
weakestLink = ri;
LowestHealth = ri.health;
}
}*/
RobotInfo weakestLink =null;
if(enemiesInRange.length >0)
weakestLink = enemiesInRange[0];
else{
}
if(weakestLink != null){
if(rc.isCoreReady()){
if(rc.getHealth() <=1 && rc.senseNearbyRobots(2,rc.getTeam().opponent()).length >0){
//rc.explode();
}
moveAsClose(rc.getLocation().directionTo(weakestLink.location));
}
}else{
//moveAsCloseToDirection(rc.getLocation().directionTo(rc.senseNearbyRobots(2, rc.getTeam())[0].location).opposite());
moveAsClose(rc.getLocation().directionTo(rc.senseEnemyHQLocation()));
}
}
public static boolean moveAsClose(Direction toMove) throws GameActionException{
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);
return true;
}
}
}
return false;
}
@Override
public void run() throws GameActionException {
// TODO Auto-generated method stub
}
}