Skip to content

Commit

Permalink
Merge pull request #156 from battlecode/cloud-sensing-fix
Browse files Browse the repository at this point in the history
Fixed cloud bug
  • Loading branch information
andywang02 authored Jan 29, 2023
2 parents 0ac19dc + d7e5308 commit 3c2a1d9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions engine/src/main/battlecode/world/RobotControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ public Anchor senseAnchor(int islandIdx) throws GameActionException {
@Override
public boolean senseCloud(MapLocation loc) throws GameActionException {
assertNotNull(loc);
if (this.getLocation().distanceSquaredTo(loc) > this.getType().visionRadiusSquared) {
int visionRadius = this.getType().visionRadiusSquared;
if (this.gameWorld.getCloud(loc)) {
visionRadius = GameConstants.CLOUD_VISION_RADIUS_SQUARED;
}
if (this.getLocation().distanceSquaredTo(loc) > visionRadius) {
throw new GameActionException(CANT_DO_THAT, "This location cannot be sensed");
}
return this.gameWorld.getCloud(loc);
Expand Down Expand Up @@ -420,9 +424,13 @@ public MapLocation[] senseNearbyCloudLocations(MapLocation center, int radiusSqu
int actualRadiusSquared = radiusSquared == -1 ? getType().visionRadiusSquared : Math.min(radiusSquared, getType().visionRadiusSquared);
MapLocation[] allLocations = gameWorld.getAllLocationsWithinRadiusSquared(center, actualRadiusSquared);
List<MapLocation> validSensedCloudLocs = new ArrayList<>();
int visionRadius = getType().visionRadiusSquared;
if (this.gameWorld.getCloud(center)) {
visionRadius = GameConstants.CLOUD_VISION_RADIUS_SQUARED;
}
for (MapLocation loc : allLocations) {
// Can't actually sense location based on radius squared
if (!getLocation().isWithinDistanceSquared(loc, getType().visionRadiusSquared)) {
if (!getLocation().isWithinDistanceSquared(loc, visionRadius)) {
continue;
}
// Check if location has a cloud
Expand Down

0 comments on commit 3c2a1d9

Please sign in to comment.