Skip to content

Commit

Permalink
Add new sensing methods for lead and gold
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mao committed Jan 5, 2022
1 parent 87e1fa0 commit d61a026
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
32 changes: 32 additions & 0 deletions engine/src/main/battlecode/common/RobotController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions engine/src/main/battlecode/world/RobotControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<MapLocation> 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<MapLocation> 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);
Expand Down

0 comments on commit d61a026

Please sign in to comment.