From 15ec49285e4048f856fc1f00dade8260cb1f674d Mon Sep 17 00:00:00 2001 From: androidmage Date: Tue, 12 Jan 2016 12:26:31 -0500 Subject: [PATCH] Turret class + locateStrongestEnemy added --- RobotPlayer.java | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/RobotPlayer.java b/RobotPlayer.java index 9aeb158..b816a22 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -61,6 +61,38 @@ else if(selftype == RobotType.SOLDIER) { } } + /** + * + * Class Turret + * + * The class outlining our turret bots + * + */ + private class Turret{ + + MapLocation enemyLocation; + + public Turret(){ + + } + + public void run(){ + while(true){ + try{ + + if(rc.isWeaponReady()){ + enemyLocation = RESOURCE_FUNCTIONS.locateStrongestEnemy(); + if(rc.canAttackLocation(enemyLocation)){ + rc.attackLocation(enemyLocation); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + } + } /** * Class Soldier * @@ -981,6 +1013,23 @@ public static MapLocation locateWeakestEnemy(){ } return null; } + public static MapLocation locateStrongestEnemy(){ + RobotInfo[] enemies = rc.senseHostileRobots(rc.getLocation(), rc.getType().sensorRadiusSquared); + if(enemies != null){ + double max = 0; + RobotInfo strongest = null; + for(RobotInfo robot: enemies){ + if(robot.health > max && robot.location.distanceSquaredTo(rc.getLocation()) >= GameConstants.TURRET_MINIMUM_RANGE){ + max = robot.health; + strongest = robot; + } + } + if(strongest != null){ + return strongest.location; + } + } + return null; + } }