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
55 changes: 55 additions & 0 deletions RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public void run(){
try{
//If it can, always tries to build Scouts.
if(rc.isCoreReady()){
RESOURCE_FUNCTIONS.escapeEnemy(rc);
if(rc.getRoundNum() % 100 == 0){
FancyMessage.sendMessage(1, 1, 1, 3);
}
Expand Down Expand Up @@ -759,6 +760,60 @@ 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);
Direction moveDirection = calculateEscapeDirection(rc, enemyLocation);
if(rc.canMove(moveDirection)){
try{
rc.move(moveDirection);
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

}
}

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

public static Direction calculateEscapeDirection(RobotController rc, MapLocation enemyLocation){
MapLocation myLocation = rc.getLocation();
int xDifference = enemyLocation.x - myLocation.x;
int yDifference = enemyLocation.y - myLocation.y;
if(xDifference>0 && yDifference>0){
return Direction.NORTH_WEST;
}
else if(xDifference>0 && yDifference<0){
return Direction.SOUTH_WEST;
}
else if(xDifference<0 && yDifference<0){
return Direction.SOUTH_EAST;
}
else if(xDifference<0 && yDifference>0){
return Direction.NORTH_EAST;
}
else if(xDifference>0){
return Direction.WEST;
}
else if(xDifference<0){
return Direction.EAST;
}
else if(yDifference>0){
return Direction.NORTH;
}
return Direction.SOUTH;

}
}

/**
Expand Down