Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public void run(){
try{
//If it can, always tries to build Scouts.
if(rc.isCoreReady()){
RESOURCE_FUNCTIONS.escapeEnemy(rc);
RESOURCE_FUNCTIONS.escapeEnemy();
if(rc.getRoundNum() % 100 == 0){
FancyMessage.sendMessage(1, 1, 1, 3);
}
Expand Down Expand Up @@ -760,12 +760,16 @@ public static boolean BUG(MapLocation target) throws GameActionException{
rc.setIndicatorString(0,"Failed outside of branch");
return false;
}
public static void escapeEnemy(RobotController rc){
MapLocation enemyLocation = locateEnemy(rc);
public static void escapeEnemy(){
RobotInfo[] enemies = locateEnemy();
if(enemies == null){
return;
}
MapLocation enemyLocation = dangerousRobotLocation(enemies);
if(enemyLocation == null){
return;
}
Direction moveDirection = calculateEscapeDirection(rc, enemyLocation);
Direction moveDirection = calculateEscapeDirection(enemyLocation);
if(rc.canMove(moveDirection)){
try{
rc.move(moveDirection);
Expand All @@ -778,20 +782,24 @@ public static void escapeEnemy(RobotController rc){
}
}

public static MapLocation locateEnemy(RobotController rc){
public static RobotInfo[] locateEnemy(){
RobotInfo[] sensedRobots = rc.senseHostileRobots(rc.getLocation(),rc.getType().sensorRadiusSquared);
MapLocation closest = null;
if(sensedRobots != null){
for(RobotInfo robot: sensedRobots){
if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){
return robot.location;
}
return sensedRobots;
}
return null;
}

public static MapLocation dangerousRobotLocation(RobotInfo[] enemies){
for(RobotInfo enemy: enemies){
if(enemy.location.distanceSquaredTo(rc.getLocation()) <= enemy.type.attackRadiusSquared){
return enemy.location;
}
}
return null;
}

public static Direction calculateEscapeDirection(RobotController rc, MapLocation enemyLocation){
public static Direction calculateEscapeDirection(MapLocation enemyLocation){
MapLocation myLocation = rc.getLocation();
int xDifference = enemyLocation.x - myLocation.x;
int yDifference = enemyLocation.y - myLocation.y;
Expand Down