Skip to content

Commit

Permalink
isSecondary consistency, better canMarkTowerPattern check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Gonzalez Hermosillo committed Jan 3, 2025
1 parent 4891e0a commit ed7669d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions engine/src/main/battlecode/common/PaintType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public boolean isAlly() {
return this == ALLY_PRIMARY || this == ALLY_SECONDARY;
}

public boolean isPrimary() {
return this == ALLY_PRIMARY || this == ENEMY_PRIMARY;
public boolean isSecondary() {
return this == ALLY_SECONDARY || this == ENEMY_SECONDARY;
}
}
3 changes: 2 additions & 1 deletion engine/src/main/battlecode/common/RobotController.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,12 +559,13 @@ public interface RobotController {
* the given location.
* This requires there to be a ruin at the location.
*
* @param type which tower pattern type should be used
* @param loc the center of the 5x5 pattern
* @return true if a tower pattern can be marked at loc
*
* @battlecode.doc.costlymethod
*/
boolean canMarkTowerPattern(MapLocation loc);
boolean canMarkTowerPattern(UnitType type, MapLocation loc);

/**
* Builds a tower by marking a 5x5 pattern centered at the given location.
Expand Down
9 changes: 5 additions & 4 deletions engine/src/main/battlecode/world/RobotControllerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,9 @@ public void removeMark(MapLocation loc) throws GameActionException {
this.gameWorld.setMarker(getTeam(), loc, 0);
}

private void assertCanMarkTowerPattern(MapLocation loc) throws GameActionException {
private void assertCanMarkTowerPattern(UnitType type, MapLocation loc) throws GameActionException {
assertIsRobotType(this.robot.getType());
assertIsTowerType(type);
assertCanActLocation(loc, GameConstants.BUILD_TOWER_RADIUS_SQUARED);

if (!this.gameWorld.hasRuin(loc)) {
Expand All @@ -583,9 +584,9 @@ private void assertCanMarkTowerPattern(MapLocation loc) throws GameActionExcepti
}

@Override
public boolean canMarkTowerPattern(MapLocation loc) {
public boolean canMarkTowerPattern(UnitType type, MapLocation loc) {
try {
assertCanMarkTowerPattern(loc);
assertCanMarkTowerPattern(type, loc);
return true;
} catch (GameActionException e) {
return false;
Expand All @@ -599,7 +600,7 @@ public void markTowerPattern(UnitType type, MapLocation loc) throws GameActionEx

@Override
public void markTowerPattern(UnitType type, MapLocation loc, int rotationAngle, boolean reflect) throws GameActionException {
assertCanMarkTowerPattern(loc);
assertCanMarkTowerPattern(type, loc);

this.robot.addPaint(-GameConstants.MARK_PATTERN_PAINT_COST);
this.gameWorld.markTowerPattern(type, getTeam(), loc, rotationAngle, reflect);
Expand Down
2 changes: 1 addition & 1 deletion example-bots/src/main/examplefuncsplayer/RobotPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public static void runSoldier(RobotController rc) throws GameActionException{
rc.move(dir);
// Mark the pattern we need to draw to build a tower here if we haven't already.
MapLocation shouldBeMarked = curRuin.getMapLocation().subtract(dir);
if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(targetLoc)){
if (rc.senseMapInfo(shouldBeMarked).getMark() == PaintType.EMPTY && rc.canMarkTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER, targetLoc)){
rc.markTowerPattern(UnitType.LEVEL_ONE_PAINT_TOWER, targetLoc);
System.out.println("Trying to build a tower at " + targetLoc);
}
Expand Down

0 comments on commit ed7669d

Please sign in to comment.