From c3b451113948dbc35e42e537597296c0caf90302 Mon Sep 17 00:00:00 2001 From: vilasopher Date: Wed, 6 Jan 2016 21:40:18 -0500 Subject: [PATCH] Update RobotPlayer.java --- RobotPlayer.java | 95 ++++++++++++++++++++++++++++++------------------ 1 file changed, 59 insertions(+), 36 deletions(-) diff --git a/RobotPlayer.java b/RobotPlayer.java index d82415e..7f3de03 100644 --- a/RobotPlayer.java +++ b/RobotPlayer.java @@ -1,6 +1,8 @@ package zombomb; //So the program knows what to call our bot import battlecode.common.*; //imports Battlecode UI + +import java.util.Collection;//Used for a collection of things import java.util.Random; //Use this instead of Math.random(); seeded by the robot's id so more likely to be random than Math.random public class RobotPlayer{ @@ -11,6 +13,9 @@ public class RobotPlayer{ * $randall: our source of all randomness * $ourTeam: our Team, to save bytecodes * $opponentTeam: Opponent's (NOT ZOMBIES) team + * + * $zombieDenLocations: locations of the zombie dens + * $enemyArchonIDs: the IDs of enemy archons * */ static RobotController rc; @@ -18,6 +23,8 @@ public class RobotPlayer{ static Team ourTeam; static Team opponentTeam; static int[] zombieRounds; + static MapLocation[] zombieDenLocations; + static Collection enemyArchonIDs; /** * run @@ -51,7 +58,7 @@ else if(selftype == RobotType.GUARD) { s.run(); } } - + /** class Guard * * The class outlining our Guard bots @@ -59,10 +66,10 @@ else if(selftype == RobotType.GUARD) { * */ private class Guard { - + public Guard() { } - + public void run() { while(true){ try{ @@ -195,7 +202,7 @@ public void run(){ last = temp; } } - //Otherwise, moves back to where it last was to try to regain them + //Otherwise, moves back to where it last was to try to regain them }else if(last != null){ if(rc.isCoreReady()){ if(rc.canMove(rc.getLocation().directionTo(last))){ @@ -312,7 +319,7 @@ public static boolean tryBuild(RobotType rt) throws GameActionException{ } public static boolean tryBuild(RobotType rt,Direction startDirection) throws GameActionException{ for(int i = 0; i < 8; i++){ - if(rc.canBuild(startDirection,rt)){ + if(rc.isCoreReady() && rc.canBuild(startDirection,rt)){ rc.build(startDirection,rt); //System.out.println("BUILT!"); return true; @@ -322,7 +329,7 @@ public static boolean tryBuild(RobotType rt,Direction startDirection) throws Gam } return false; } - + /** * boolean tryAttackLocation * @@ -333,13 +340,13 @@ public static boolean tryBuild(RobotType rt,Direction startDirection) throws Gam * */ public static boolean tryAttackLocation(MapLocation loc) throws GameActionException { - boolean canAttack = rc.canAttackLocation(loc); - if (canAttack) { + if (rc.isWeaponReady() && rc.canAttackLocation(loc)) { rc.attackLocation(loc); + return true; } - return canAttack; + return false; } - + /** * MapLocation findLargestPileOfParts * @@ -352,7 +359,7 @@ public static Tuple findLargestPileOfParts() { MapLocation myLocation = rc.getLocation(); int sensingRadiusSquared = rc.getType().sensorRadiusSquared; MapLocation[] visibleLocations = MapLocation.getAllMapLocationsWithinRadiusSq(myLocation, sensingRadiusSquared); - + // find the largest pile of parts double maxPileSize = 0; MapLocation maxPileLocation = myLocation; @@ -363,10 +370,10 @@ public static Tuple findLargestPileOfParts() { maxPileLocation = loc; } } - + // create Tuple Tuple locationAndSize = new Tuple(maxPileLocation, maxPileSize); - + return locationAndSize; } @@ -417,6 +424,7 @@ public static boolean moveAsFarAwayAsPossibleFrom(MapLocation epicenter) throws rc.setIndicatorString(1,"max:none"); return false; } + /** * boolean trySendMessage * @@ -447,7 +455,7 @@ public static boolean trySendMessage(Tuple information,int type rc.broadcastMessageSignal(first,second,radiusSqr); return true; } - + /** * RobotType chooseRobotType * @param none @@ -463,46 +471,61 @@ public static RobotType chooseRobotType() { if(Math.random()*3>1) { return RobotType.SCOUT; } - if(numberOfRobotsInRadius(RobotType.GUARD,3,ourTeam) == 7){ + if(numberOfRobotsInRadiusAndThoseRobots(RobotType.GUARD,3,ourTeam).first == 7){ return RobotType.SCOUT; } return RobotType.GUARD; } - + /** * Returns the number of robots within a given radius squared * @param type the type of robot to look for * @param radiusSqr the squared radius * @param team the team the robot should be on - * @return the number of robots nearby + * @return a tuple containing the number of robots nearby and the array of all robots nearby */ - public static int numberOfRobotsInRadius(RobotType type,int radiusSqr,Team team){ + public static Tuple numberOfRobotsInRadiusAndThoseRobots(RobotType type,int radiusSqr,Team team){ int count = 0; RobotInfo[] robats = rc.senseNearbyRobots(radiusSqr,team); if(type == null){ - return robats.length; + Tuple thingToReturn = new Tuple(robats.length, robats); + return thingToReturn; } for(int i = 0; i < robats.length; i++){ if(robats[i].type.equals(type)){ count++; } } - return count; + Tuple returnThing = new Tuple(count, robats); + return returnThing; + } + + /** + * Collects the ID of enemy archons within sight range + * adds the IDs to the static collection enemyArchonIDs + */ + public static void collectEnemyArchonID() { + Tuple robs = numberOfRobotsInRadiusAndThoseRobots(RobotType.ARCHON, rc.getType().sensorRadiusSquared, opponentTeam); + if (robs.first > 0) { + for (RobotInfo rob : robs.second) { + enemyArchonIDs.add(rob.ID); + } + } } } - + /** * Tuple * * a simple tuple class so that tuples can be used. */ public static class Tuple { - public X first; - public Y second; - public Tuple(X first, Y second) { - this.first = first; - this.second = second; - } + public X first; + public Y second; + public Tuple(X first, Y second) { + this.first = first; + this.second = second; + } } /** @@ -535,15 +558,15 @@ public static Tuple decrypt(Tuple inputs){ encryptor |= keyIn & 0b1111; } int first = (inputs.first ^ encryptor) >> 8; - int second = (inputs.second ^ encryptor); - boolean[] bit = new boolean[56]; - for(int i = 0; i < 24; i++){ - bit[i] = (first & (1 << i)) != 0; - } - for(int i = 0; i < 32; i++){ - bit[i + 24] = (second & (1 << i)) != 0; - } - return new Tuple(typeIn,bit); + int second = (inputs.second ^ encryptor); + boolean[] bit = new boolean[56]; + for(int i = 0; i < 24; i++){ + bit[i] = (first & (1 << i)) != 0; + } + for(int i = 0; i < 32; i++){ + bit[i + 24] = (second & (1 << i)) != 0; + } + return new Tuple(typeIn,bit); } } }