Skip to content

Commit 2d86fa8

Browse files
authored
Merge pull request #58 from battlecode/engine-bugfix-1
Bug fixes and naming convention fixes for engine
2 parents bc23d5d + 1d35d0e commit 2d86fa8

3 files changed

Lines changed: 27 additions & 22 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -822,11 +822,12 @@ public interface RobotController {
822822
* for increasing bite strength
823823
*
824824
* @param loc the target location to attack
825+
* @param cheeseAmount amount of cheese to spend on the attack
825826
* @throws GameActionException if conditions for attacking are not satisfied
826827
*
827828
* @battlecode.doc.costlymethod
828829
*/
829-
void attack(MapLocation loc, int cheese) throws GameActionException;
830+
void attack(MapLocation loc, int cheeseAmount) throws GameActionException;
830831

831832
// ***********************************
832833
// ****** COMMUNICATION METHODS ******

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

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,12 @@ public void setIndicatorString(String string) {
425425
}
426426

427427
/**
428-
* Sets the location of the robot.
428+
* Sets the location of the robot by translating it.
429429
*
430430
* @param dx # amount to translate in x direction
431431
* @param dy # amount to translate in y direction
432432
*/
433-
public void setLocation(int dx, int dy) {
433+
public void translateLocation(int dx, int dy) {
434434
MapLocation[] beforeLocs = this.getAllPartLocations();
435435
for (MapLocation partLoc : beforeLocs) {
436436
this.gameWorld.removeRobot(partLoc);
@@ -777,8 +777,9 @@ public void hitGround() {
777777

778778
this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
779779

780-
if (this.health > 0)
780+
if (this.health > 0) {
781781
this.gameWorld.addRobot(this.location, this);
782+
}
782783

783784
setMovementCooldownTurns(this.movementCooldownTurns + GameConstants.HIT_GROUND_COOLDOWN);
784785
setActionCooldownTurns(this.actionCooldownTurns + GameConstants.HIT_GROUND_COOLDOWN);
@@ -815,10 +816,6 @@ public void travelFlying(boolean isSecondMove) {
815816
return;
816817
}
817818

818-
System.out
819-
.println("Robot flyingggg: " + this.ID + " " + this.thrownDir + " " + this.health + " " + isSecondMove);
820-
// use the internal location
821-
822819
MapLocation newLoc = this.location.add(this.thrownDir);
823820

824821
if (!this.gameWorld.getGameMap().onTheMap(newLoc)) {
@@ -837,8 +834,7 @@ public void travelFlying(boolean isSecondMove) {
837834
return;
838835
}
839836

840-
MapLocation nextLocation = new MapLocation(this.thrownDir.dx, this.thrownDir.dy);
841-
this.setInternalLocationOnly(nextLocation);
837+
this.setInternalLocationOnly(newLoc);
842838
}
843839

844840
/**
@@ -944,23 +940,30 @@ public void pounce(int[] delta) {
944940
int dy = delta[1];
945941

946942
MapLocation[] oldLocs = this.getAllPartLocations();
943+
947944
for (MapLocation partLoc : oldLocs) {
948945
// shift location by dx, dy
949946
MapLocation translatedLoc = partLoc.translate(dx, dy);
950947
InternalRobot crushedRobot = this.gameWorld.getRobot(translatedLoc);
948+
951949
if (crushedRobot != null && (crushedRobot.getID() != this.ID)) {
952950
// destroy robot
953951
crushedRobot.addHealth(-crushedRobot.getHealth());
954952
}
955953
}
956954

957955
// actually translate the cat
958-
this.setLocation(dx, dy);
956+
this.translateLocation(dx, dy);
957+
958+
MapLocation[] newLocs = this.getAllPartLocations();
959+
960+
for (MapLocation partLoc : newLocs) {
961+
this.controller.processTrapsAtLocation(partLoc);
962+
}
959963

960964
// incur double the movement cooldown
961965
this.addMovementCooldownTurns(this.dir);
962966
this.addMovementCooldownTurns(this.dir);
963-
964967
}
965968

966969
public MapLocation getCatCornerByChirality(){

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

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,7 @@ public void processTrapsAtLocation(MapLocation loc) {
797797
if (trap.getTeam() == this.robot.getTeam() || wrongTrapType) {
798798
continue;
799799
}
800+
800801
this.gameWorld.triggerTrap(trap, robot);
801802

802803
}
@@ -820,7 +821,7 @@ public void move(Direction d) throws GameActionException {
820821
processTrapsAtLocation(newLoc);
821822
}
822823

823-
this.robot.setLocation(d.dx, d.dy);
824+
this.robot.translateLocation(d.dx, d.dy);
824825
this.robot.addMovementCooldownTurns(d);
825826

826827
}
@@ -934,11 +935,11 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
934935
throw new GameActionException(CANT_DO_THAT, "Rats cannot attack squares with walls or dirt on them!");
935936

936937
if (this.gameWorld.getTeamInfo().getCheese(this.getTeam()) + this.getAllCheese() < cheeseConsumed) {
937-
throw new RuntimeException("Not enough cheese to bite!");
938+
throw new GameActionException(CANT_DO_THAT, "Not enough cheese to bite!");
938939
}
939940

940941
if (this.getType() == UnitType.CAT) {
941-
throw new RuntimeException("Unit must be a baby rat or rat king to bite!");
942+
throw new GameActionException(CANT_DO_THAT, "Unit must be a baby rat or rat king to bite!");
942943
}
943944
}
944945

@@ -980,7 +981,7 @@ public boolean canAttack(MapLocation loc) {
980981
@Override
981982
public boolean canAttack(MapLocation loc, int cheeseConsumed) {
982983
try {
983-
assertCanAttack(loc, 0);
984+
assertCanAttack(loc, cheeseConsumed);
984985
return true;
985986
} catch (GameActionException e) {
986987
return false;
@@ -1203,10 +1204,10 @@ public void assertCanThrowRat(Direction dir) throws GameActionException {
12031204
if (!this.robot.isCarryingRobot())
12041205
throw new GameActionException(CANT_DO_THAT, "This rat is not carrying any rat!");
12051206
if (!this.gameWorld.getGameMap().onTheMap(nextLoc)) {
1206-
throw new RuntimeException("Cannot throw outside of map!");
1207+
throw new GameActionException(CANT_DO_THAT, "Cannot throw outside of map!");
12071208
}
12081209
if (!this.gameWorld.isPassable(nextLoc) || (this.gameWorld.getRobot(nextLoc) != null)) {
1209-
throw new RuntimeException("There must be at least 1 empty space in front the throwing rat!");
1210+
throw new GameActionException(CANT_DO_THAT, "There must be at least 1 empty space in front the throwing rat!");
12101211
}
12111212
}
12121213

@@ -1219,10 +1220,10 @@ public void assertCanDropRat(Direction dir) throws GameActionException {
12191220
if (!this.robot.isCarryingRobot())
12201221
throw new GameActionException(CANT_DO_THAT, "This rat is not carrying any rat!");
12211222
if (!this.gameWorld.getGameMap().onTheMap(nextLoc)) {
1222-
throw new RuntimeException("Cannot drop outside of map!");
1223+
throw new GameActionException(CANT_DO_THAT, "Cannot drop outside of map!");
12231224
}
12241225
if (!this.gameWorld.isPassable(nextLoc) || (this.gameWorld.getRobot(nextLoc) != null)) {
1225-
throw new RuntimeException("Can only drop rats into empty spaces!");
1226+
throw new GameActionException(CANT_DO_THAT, "Can only drop rats into empty spaces!");
12261227
}
12271228
}
12281229

@@ -1263,9 +1264,9 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
12631264
assertIsActionReady();
12641265

12651266
if (!this.robot.getType().isThrowingType()) {
1266-
throw new RuntimeException("Unit must be a rat to grab other rats");
1267+
throw new GameActionException(CANT_DO_THAT, "Unit must be a rat to grab other rats");
12671268
} else if (this.robot.isCarryingRobot()) {
1268-
throw new RuntimeException("Already carrying a rat");
1269+
throw new GameActionException(CANT_DO_THAT, "Already carrying a rat");
12691270
}
12701271
// Must be a rat-type
12711272
if (!this.robot.getType().isBabyRatType()) {

0 commit comments

Comments
 (0)