diff --git a/engine/src/main/battlecode/common/RobotController.java b/engine/src/main/battlecode/common/RobotController.java index 3f593bb4..35f19094 100644 --- a/engine/src/main/battlecode/common/RobotController.java +++ b/engine/src/main/battlecode/common/RobotController.java @@ -340,6 +340,38 @@ public strictfp interface RobotController { */ int senseGold(MapLocation loc) throws GameActionException; + /** + * Return all locations that contain a nonzero amount of lead, within a + * specified radius of your robot location. + * If radiusSquared is larger than the robot's vision radius, uses the robot's + * vision radius instead. + * + * Checks that radiusSquared is non-negative. + * + * @param radiusSquared the squared radius of all locations to be returned + * @return all locations that contain a nonzero amount of lead within the radius + * @throws GameActionException if the radius is negative + * + * @battlecode.doc.costlymethod + */ + MapLocation[] senseNearbyLocationsWithLead(int radiusSquared) throws GameActionException; + + /** + * Return all locations that contain a nonzero amount of gold, within a + * specified radius of your robot location. + * If radiusSquared is larger than the robot's vision radius, uses the robot's + * vision radius instead. + * + * Checks that radiusSquared is non-negative. + * + * @param radiusSquared the squared radius of all locations to be returned + * @return all locations that contain a nonzero amount of gold within the radius + * @throws GameActionException if the radius is negative + * + * @battlecode.doc.costlymethod + */ + MapLocation[] senseNearbyLocationsWithGold(int radiusSquared) throws GameActionException; + /** * Returns the location adjacent to current location in the given direction. * diff --git a/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt b/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt index 74c6406b..7241ccf5 100644 --- a/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt +++ b/engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt @@ -76,6 +76,8 @@ battlecode/common/RobotController/repair 0 tru battlecode/common/RobotController/resign 0 true battlecode/common/RobotController/senseGold 5 true battlecode/common/RobotController/senseLead 5 true +battlecode/common/RobotController/senseNearbyLocationsWithLead 100 true +battlecode/common/RobotController/senseNearbyLocationsWithGold 100 true battlecode/common/RobotController/senseNearbyRobots 100 true battlecode/common/RobotController/senseRobot 25 true battlecode/common/RobotController/senseRobotAtLocation 25 true diff --git a/engine/src/main/battlecode/world/RobotControllerImpl.java b/engine/src/main/battlecode/world/RobotControllerImpl.java index 809538d8..558ff198 100644 --- a/engine/src/main/battlecode/world/RobotControllerImpl.java +++ b/engine/src/main/battlecode/world/RobotControllerImpl.java @@ -290,6 +290,38 @@ public int senseGold(MapLocation loc) throws GameActionException { return this.gameWorld.getGold(loc); } + @Override + public MapLocation[] senseNearbyLocationsWithLead(int radiusSquared) throws GameActionException { + if (radiusSquared < 0) + throw new GameActionException(CANT_DO_THAT, + "Radius squared must be non-negative."); + radiusSquared = Math.min(radiusSquared, getType().visionRadiusSquared); + ArrayList locations = new ArrayList<>(); + for (MapLocation m : this.gameWorld.getAllLocationsWithinRadiusSquared(getLocation(), radiusSquared)) { + if (this.gameWorld.getLead(m) > 0) { + locations.add(m); + } + } + MapLocation[] result = new MapLocation[locations.size()]; + return locations.toArray(result); + } + + @Override + public MapLocation[] senseNearbyLocationsWithGold(int radiusSquared) throws GameActionException { + if (radiusSquared < 0) + throw new GameActionException(CANT_DO_THAT, + "Radius squared must be non-negative."); + radiusSquared = Math.min(radiusSquared, getType().visionRadiusSquared); + ArrayList locations = new ArrayList<>(); + for (MapLocation m : this.gameWorld.getAllLocationsWithinRadiusSquared(getLocation(), radiusSquared)) { + if (this.gameWorld.getGold(m) > 0) { + locations.add(m); + } + } + MapLocation[] result = new MapLocation[locations.size()]; + return locations.toArray(result); + } + @Override public MapLocation adjacentLocation(Direction dir) { return getLocation().add(dir);