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
46 changes: 42 additions & 4 deletions RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.ArrayList;
import java.lang.Math;

public class RobotPlayer{
/**
Expand Down Expand Up @@ -112,13 +113,14 @@ public void run() {
RESOURCE_FUNCTIONS.BUG(enemyArchonLocation);
}
if(rc.isWeaponReady()){
RobotInfo[] robots = rc.senseNearbyRobots();
/* RobotInfo[] robots = rc.senseNearbyRobots();
for(RobotInfo robot: robots) {
if((robot.team == Team.ZOMBIE || robot.team == opponentTeam) && rc.canAttackLocation(robot.location)) {
rc.attackLocation(robot.location);
break;
}
}
}*/
RESOURCE_FUNCTIONS.attackWeakestEnemy();
}
// If there are enough scouts around, move out towards enemy Archon
/* (mostRecentEnemyArchonLocations.size() > 0 && RESOURCE_FUNCTIONS.numberOfRobotsInRadiusAndThoseRobots(RobotType.SOLDIER, RobotType.SOLDIER.sensorRadiusSquared, rc.getTeam()).first > 5) {
Expand Down Expand Up @@ -183,7 +185,7 @@ public void run() {
}
if(rc.isWeaponReady()){
RobotInfo[] robots = rc.senseNearbyRobots();
for(RobotInfo robot: robots) {
/*for(RobotInfo robot: robots) {
if((robot.team == Team.ZOMBIE) && rc.canAttackLocation(robot.location)) {
rc.attackLocation(robot.location);
break;
Expand All @@ -194,7 +196,9 @@ public void run() {
rc.attackLocation(robot.location);
break;
}
}
}*/

RESOURCE_FUNCTIONS.attackWeakestEnemy();
//If didn't attack anyone that is adjacent
if(rc.isWeaponReady()){
MapLocation target = null;
Expand Down Expand Up @@ -844,6 +848,40 @@ else if(yDifference>0){
return Direction.SOUTH;

}

public static void attackWeakestEnemy(){
MapLocation weakestEnemyLocation = locateWeakestEnemy();
if(weakestEnemyLocation==null){
return;
}
try{
rc.attackLocation(weakestEnemyLocation);
}
catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}

}

public static MapLocation locateWeakestEnemy(){
RobotInfo[] sensedRobots = rc.senseHostileRobots(rc.getLocation(),Math.min(rc.getType().sensorRadiusSquared, rc.getType().attackRadiusSquared));
RobotInfo weakest=null;
if(sensedRobots != null){
for(RobotInfo robot: sensedRobots){
if(robot.team == opponentTeam || robot.team == Team.ZOMBIE){
if(weakest == null || robot.health<weakest.health){
weakest=robot;
}
}
}
if(weakest!= null){
return weakest.location;
}
}
return null;
}

}

/**
Expand Down