From f83fb5f0730de7101204973e747e8e5e3739d2f0 Mon Sep 17 00:00:00 2001 From: katiekang1998 Date: Sun, 10 Jan 2016 15:26:20 -0500 Subject: [PATCH] attackweakestenemy --- RobotPlayer.java | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index 2ab91b1..ea4883d 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -5,6 +5,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.ArrayList; +import java.lang.Math; public class RobotPlayer{ /** @@ -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) { @@ -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; @@ -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; @@ -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