From ed7669d3008647a34e38f0de067c732f2b3c785e Mon Sep 17 00:00:00 2001 From: Ian Gonzalez Hermosillo Date: Fri, 3 Jan 2025 00:55:00 -0500 Subject: [PATCH] isSecondary consistency, better canMarkTowerPattern check --- engine/src/main/battlecode/common/PaintType.java | 4 ++-- engine/src/main/battlecode/common/RobotController.java | 3 ++- .../src/main/battlecode/world/RobotControllerImpl.java | 9 +++++---- .../src/main/examplefuncsplayer/RobotPlayer.java | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/engine/src/main/battlecode/common/PaintType.java b/engine/src/main/battlecode/common/PaintType.java index 4a44ae8f..7a7b13ce 100644 --- a/engine/src/main/battlecode/common/PaintType.java +++ b/engine/src/main/battlecode/common/PaintType.java @@ -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; } } diff --git a/engine/src/main/battlecode/common/RobotController.java b/engine/src/main/battlecode/common/RobotController.java index a3da6859..cc8d46f7 100644 --- a/engine/src/main/battlecode/common/RobotController.java +++ b/engine/src/main/battlecode/common/RobotController.java @@ -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. diff --git a/engine/src/main/battlecode/world/RobotControllerImpl.java b/engine/src/main/battlecode/world/RobotControllerImpl.java index 0633c0ce..4e62c0a4 100644 --- a/engine/src/main/battlecode/world/RobotControllerImpl.java +++ b/engine/src/main/battlecode/world/RobotControllerImpl.java @@ -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)) { @@ -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; @@ -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); diff --git a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java index 8f842064..daeefc9b 100644 --- a/example-bots/src/main/examplefuncsplayer/RobotPlayer.java +++ b/example-bots/src/main/examplefuncsplayer/RobotPlayer.java @@ -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); }