Skip to content

Commit c9582b0

Browse files
author
Ian Gonzalez Hermosillo
committed
add PaintType.isEnemy() UnitType.getBaseType() and RobotController.canPaint() methods
1 parent dbc355e commit c9582b0

5 files changed

Lines changed: 52 additions & 0 deletions

File tree

engine/src/main/battlecode/common/PaintType.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public boolean isAlly() {
1111
return this == ALLY_PRIMARY || this == ALLY_SECONDARY;
1212
}
1313

14+
public boolean isEnemy(){
15+
return this == ENEMY_PRIMARY || this == ENEMY_SECONDARY;
16+
}
17+
1418
public boolean isSecondary() {
1519
return this == ALLY_SECONDARY || this == ENEMY_SECONDARY;
1620
}

engine/src/main/battlecode/common/RobotController.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,16 @@ public interface RobotController {
676676
// ***** ATTACK / HEAL ********
677677
// ****************************
678678

679+
/**
680+
* Tests whether this robot can paint the given location.
681+
*
682+
* @param loc target location to paint
683+
* @return true if rc.attack(loc) will paint the given location
684+
*
685+
* @battlecode.doc.costlymethod
686+
*/
687+
boolean canPaint(MapLocation loc);
688+
679689
/**
680690
* Tests whether this robot can attack the given location. Types of
681691
* attacks for specific units determine whether or not towers, other
@@ -857,6 +867,7 @@ public interface RobotController {
857867
* @param red the red component of the dot's color
858868
* @param green the green component of the dot's color
859869
* @param blue the blue component of the dot's color
870+
* @throws GameActionException if the location is off the map
860871
*
861872
* @battlecode.doc.costlymethod
862873
*/
@@ -870,6 +881,7 @@ public interface RobotController {
870881
* @param red the red component of the line's color
871882
* @param green the green component of the line's color
872883
* @param blue the blue component of the line's color
884+
* @throws GameActionException if any location is off the map
873885
*
874886
* @battlecode.doc.costlymethod
875887
*/

engine/src/main/battlecode/common/UnitType.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,18 @@ public UnitType getNextLevel(){
7878
}
7979
}
8080

81+
public UnitType getBaseType(){
82+
switch (this){
83+
case LEVEL_TWO_DEFENSE_TOWER: return LEVEL_ONE_DEFENSE_TOWER;
84+
case LEVEL_THREE_DEFENSE_TOWER: return LEVEL_ONE_DEFENSE_TOWER;
85+
case LEVEL_TWO_PAINT_TOWER: return LEVEL_ONE_PAINT_TOWER;
86+
case LEVEL_THREE_PAINT_TOWER: return LEVEL_ONE_PAINT_TOWER;
87+
case LEVEL_TWO_MONEY_TOWER: return LEVEL_ONE_MONEY_TOWER;
88+
case LEVEL_THREE_MONEY_TOWER: return LEVEL_ONE_MONEY_TOWER;
89+
default: return this;
90+
}
91+
}
92+
8193
UnitType(int paintCost, int moneyCost, int attackCost, int health, int level, int paintCapacity, int actionCooldown, int actionRadiusSquared, int attackStrength, int aoeAttackStrength, int paintPerTurn, int moneyPerTurn) {
8294
this.paintCost = paintCost;
8395
this.moneyCost = moneyCost;

engine/src/main/battlecode/instrumenter/bytecode/resources/MethodCosts.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ battlecode/common/RobotController/getResourcePattern 2 tru
2626
battlecode/common/RobotController/getTowerPattern 2 true
2727
battlecode/common/RobotController/adjacentLocation 1 true
2828
battlecode/common/RobotController/attack 0 true
29+
battlecode/common/RobotController/canPaint 10 true
2930
battlecode/common/RobotController/canAttack 10 true
3031
battlecode/common/RobotController/canMopSwing 10 true
3132
battlecode/common/RobotController/mopSwing 0 true
@@ -111,11 +112,13 @@ battlecode/common/Message/getBytes 3 fal
111112
battlecode/common/Message/toString 5 false
112113
battlecode/common/Message/copy 5 false
113114
battlecode/common/PaintType/isAlly 2 false
115+
battlecode/common/PaintType/isEnemy 2 false
114116
battlecode/common/PaintType/isSecondary 2 false
115117
battlecode/common/UnitType/isRobotType 3 false
116118
battlecode/common/UnitType/isTowerType 3 false
117119
battlecode/common/UnitType/canUpgradeType 3 false
118120
battlecode/common/UnitType/getNextLevel 3 false
121+
battlecode/common/UnitType/getBaseType 3 false
119122
java/lang/Math/IEEEremainder 1 false
120123
java/lang/Math/abs 1 false
121124
java/lang/Math/acos 1 false

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,27 @@ public void completeResourcePattern(MapLocation loc) throws GameActionException
832832
// ****** ATTACK / HEAL ********
833833
// *****************************
834834

835+
@Override
836+
public boolean canPaint(MapLocation loc){
837+
assertNotNull(loc);
838+
if (!onTheMap(loc))
839+
return false;
840+
// towers and moppers cannot paint tiles
841+
if (getType().isTowerType() || getType() == UnitType.MOPPER){
842+
return false;
843+
}
844+
if (getType() == UnitType.SOLDIER){
845+
if (loc.distanceSquaredTo(this.robot.getLocation()) > UnitType.SOLDIER.actionRadiusSquared)
846+
return false;
847+
return this.gameWorld.isPaintable(loc) && this.gameWorld.teamFromPaint(this.gameWorld.getPaint(loc)) != getTeam().opponent();
848+
}
849+
else{
850+
if (loc.distanceSquaredTo(this.robot.getLocation()) > UnitType.SPLASHER.actionRadiusSquared)
851+
return false;
852+
return this.gameWorld.isPaintable(loc);
853+
}
854+
}
855+
835856
private void assertCanAttackSoldier(MapLocation loc) throws GameActionException {
836857
assertIsActionReady();
837858
assertCanActLocation(loc, UnitType.SOLDIER.actionRadiusSquared);

0 commit comments

Comments
 (0)