Skip to content

Commit 76ca2b8

Browse files
Fix pattern center check
1 parent f1c13ae commit 76ca2b8

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

engine/src/main/battlecode/world/GameWorld.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,12 +576,12 @@ public int getTowerPattern(UnitType towerType) {
576576
return this.patternArray[towerTypeToPatternIndex(towerType)];
577577
}
578578

579-
public boolean isValidPatternCenter(MapLocation loc) {
579+
public boolean isValidPatternCenter(MapLocation loc, boolean isTower) {
580580
return (!(loc.x < GameConstants.PATTERN_SIZE / 2
581581
|| loc.y < GameConstants.PATTERN_SIZE / 2
582582
|| loc.x >= gameMap.getWidth() - (GameConstants.PATTERN_SIZE - 1) / 2
583583
|| loc.y >= gameMap.getHeight() - (GameConstants.PATTERN_SIZE - 1) / 2
584-
)) && areaIsPaintable(loc) ;
584+
)) && (isTower || areaIsPaintable(loc)) ;
585585
}
586586

587587
// checks that location has no walls/ruins in the surrounding 5x5 area

engine/src/main/battlecode/world/RobotControllerImpl.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ private void assertCanMarkTowerPattern(UnitType type, MapLocation loc) throws Ga
583583
+ ") because the center is not a ruin");
584584
}
585585

586-
if (!this.gameWorld.isValidPatternCenter(loc)) {
586+
if (!this.gameWorld.isValidPatternCenter(loc, true)) {
587587
throw new GameActionException(CANT_DO_THAT,
588588
"Cannot mark tower pattern centered at (" + loc.x + ", " + loc.y
589589
+ ") because it is too close to the edge of the map");
@@ -678,10 +678,10 @@ private void assertCanMarkResourcePattern(MapLocation loc) throws GameActionExce
678678
assertIsRobotType(this.robot.getType());
679679
assertCanActLocation(loc, GameConstants.RESOURCE_PATTERN_RADIUS_SQUARED);
680680

681-
if (!this.gameWorld.isValidPatternCenter(loc)) {
681+
if (!this.gameWorld.isValidPatternCenter(loc, false)) {
682682
throw new GameActionException(CANT_DO_THAT,
683683
"Cannot mark resource pattern centered at (" + loc.x + ", " + loc.y
684-
+ ") because it is too close to the edge of the map");
684+
+ ") because it is blocked or too close to the edge of the map");
685685
}
686686

687687
if (this.robot.getPaint() < GameConstants.MARK_PATTERN_PAINT_COST){
@@ -750,7 +750,7 @@ private void assertCanCompleteTowerPattern(UnitType type, MapLocation loc) throw
750750
+ ") because the team does not have enough money!");
751751
}
752752

753-
if (!this.gameWorld.isValidPatternCenter(loc)) {
753+
if (!this.gameWorld.isValidPatternCenter(loc, true)) {
754754
throw new GameActionException(CANT_DO_THAT,
755755
"Cannot complete tower pattern centered at (" + loc.x + ", " + loc.y
756756
+ ") because it is too close to the edge of the map");
@@ -802,10 +802,10 @@ private void assertCanCompleteResourcePattern(MapLocation loc) throws GameAction
802802
assertIsRobotType(this.robot.getType());
803803
assertCanActLocation(loc, GameConstants.RESOURCE_PATTERN_RADIUS_SQUARED);
804804

805-
if (!this.gameWorld.isValidPatternCenter(loc)) {
805+
if (!this.gameWorld.isValidPatternCenter(loc, false)) {
806806
throw new GameActionException(CANT_DO_THAT,
807807
"Cannot complete resource pattern centered at (" + loc.x + ", " + loc.y
808-
+ ") because it is too close to the edge of the map");
808+
+ ") because it is blocked or too close to the edge of the map");
809809
}
810810

811811
boolean valid = this.gameWorld.checkResourcePattern(this.robot.getTeam(), loc);

0 commit comments

Comments
 (0)