Skip to content

Commit ceccb59

Browse files
committed
delete unnecessary checks in internalrobot
1 parent 1b1f2be commit ceccb59

3 files changed

Lines changed: 18 additions & 32 deletions

File tree

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,34 +1076,43 @@ public void destroyRobot(int id, boolean fromException, boolean fromDamage) {
10761076
} else if (robot.getType().isCatType()) {
10771077
this.numCats -= 1;
10781078
}
1079+
10791080
for (MapLocation robotLoc : robot.getAllPartLocations()) {
10801081
removeRobot(robotLoc);
10811082
}
1083+
10821084
if (robot.isCarryingRobot()) {
10831085
InternalRobot carryingRobot = robot.getRobotBeingCarried();
10841086
carryingRobot.getDropped(loc);
10851087
}
1088+
10861089
if (robot.isGrabbedByRobot()) {
10871090
InternalRobot carrier = robot.getGrabbedByRobot();
10881091
robot.clearGrabbedByRobot();
1092+
10891093
if (carrier != null && carrier.getRobotBeingCarried() == robot) {
10901094
carrier.clearCarryingRobot();
10911095
}
10921096
}
1097+
10931098
if (robot.getCheese() > 0) {
10941099
addCheese(loc, robot.getCheese());
10951100
matchMaker.addCheeseSpawnAction(loc, robot.getCheese());
10961101
}
10971102
}
1103+
10981104
controlProvider.robotKilled(robot);
10991105
objectInfo.destroyRobot(id);
1100-
if (fromDamage || fromException)
1106+
1107+
if (fromDamage || fromException) {
11011108
matchMaker.addDieAction(id, fromException);
1102-
else
1109+
} else {
11031110
matchMaker.addDied(id);
1111+
}
11041112

1105-
if (robot.getType() != UnitType.CAT)
1113+
if (robot.getType() != UnitType.CAT) {
11061114
this.currentNumberUnits[robot.getTeam().ordinal()] -= 1;
1115+
}
11071116

11081117
// check win
11091118
if (robot.getType() == UnitType.RAT_KING && this.getTeamInfo().getNumRatKings(robot.getTeam()) == 0) {
@@ -1121,6 +1130,7 @@ public void setProfilerCollection(Team team, ProfilerCollection profilerCollecti
11211130
if (profilerCollections == null) {
11221131
profilerCollections = new HashMap<>();
11231132
}
1133+
11241134
profilerCollections.put(team, profilerCollection);
11251135
}
11261136
}

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

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.util.*;
44

5-
import battlecode.world.CatStateType;
65
import battlecode.common.Direction;
76
import battlecode.common.GameActionException;
87
import battlecode.common.GameConstants;
@@ -616,7 +615,6 @@ public void scratch(MapLocation loc) {
616615
}
617616

618617
public void grabRobot(MapLocation loc) {
619-
620618
this.robotBeingCarried = this.gameWorld.getRobot(loc);
621619
this.robotBeingCarried.getGrabbed(this); // Notify the grabbed robot that it has been picked up
622620
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
@@ -627,21 +625,7 @@ public void grabRobot(MapLocation loc) {
627625
}
628626

629627
public void dropRobot(Direction dir) {
630-
if (!this.type.isThrowingType()) {
631-
throw new RuntimeException("Unit must be a rat to drop other rats");
632-
} else if (!this.isCarryingRobot()) {
633-
throw new RuntimeException("Not carrying a robot to drop");
634-
}
635628
MapLocation dropLoc = this.getLocation().add(dir);
636-
if (!this.gameWorld.getGameMap().onTheMap(dropLoc)) {
637-
throw new RuntimeException("Cannot drop outside of map");
638-
} else if (this.gameWorld.getRobot(dropLoc) != null) {
639-
throw new RuntimeException("Cannot drop into occupied space");
640-
} else if (!this.gameWorld.isPassable(dropLoc)) {
641-
throw new RuntimeException("Cannot drop into impassable terrain");
642-
}
643-
644-
// Drop the robot
645629
this.robotBeingCarried.getDropped(dropLoc);
646630
this.robotBeingCarried = null;
647631
}
@@ -676,10 +660,12 @@ private void swapGrabber() {
676660
private void getGrabbed(InternalRobot grabber) {
677661
this.grabbedByRobot = grabber;
678662
this.gameWorld.removeRobot(getLocation());
663+
679664
if (this.isCarryingRobot()) { // If we were carrying a robot, drop it
680665
this.robotBeingCarried.getDropped(getLocation());
681666
this.robotBeingCarried = null;
682667
}
668+
683669
this.setInternalLocationOnly(grabber.getLocation());
684670

685671
if (grabber.getTeam() != this.getTeam()) {
@@ -689,19 +675,6 @@ private void getGrabbed(InternalRobot grabber) {
689675
}
690676

691677
public void throwRobot() {
692-
if (!this.type.isThrowingType()) {
693-
throw new RuntimeException("Unit must be a rat to throw other rats");
694-
} else if (!this.isCarryingRobot()) {
695-
throw new RuntimeException("Not carrying a robot to throw");
696-
}
697-
if (!this.gameWorld.getGameMap().onTheMap(this.getLocation().add(this.dir))) {
698-
throw new RuntimeException("Cannot throw outside of map");
699-
} else if (this.gameWorld.getRobot(this.getLocation().add(this.dir)) != null
700-
&& this.gameWorld.getRobot(this.getLocation().add(this.dir)).getType() != UnitType.CAT) {
701-
throw new RuntimeException("Cannot throw into a space occupied by another rat");
702-
}
703-
704-
// Throw the robot
705678
this.robotBeingCarried.getThrown(this.dir);
706679
this.gameWorld.getMatchMaker().addThrowAction(this.robotBeingCarried.getID(),
707680
this.getLocation().add(this.dir));
@@ -737,6 +710,7 @@ public void getDropped(MapLocation loc) {
737710
} else if (!this.gameWorld.isPassable(loc)) {
738711
throw new RuntimeException("Cannot drop into impassable terrain");
739712
}
713+
740714
this.grabbedByRobot = null;
741715
this.remainingCarriedDuration = 0;
742716
this.setInternalLocationOnly(loc);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@ public void transferCheese(MapLocation loc, int amount) throws GameActionExcepti
12281228
public void assertCanThrowRat(Direction dir) throws GameActionException {
12291229
assertIsActionReady();
12301230
MapLocation nextLoc = this.getLocation().add(dir);
1231+
12311232
if (!this.robot.getType().isBabyRatType()) {
12321233
throw new GameActionException(CANT_DO_THAT, "Only rats can throw other rats!");
12331234
}
@@ -1244,6 +1245,7 @@ public void assertCanThrowRat(Direction dir) throws GameActionException {
12441245
public void assertCanDropRat(Direction dir) throws GameActionException {
12451246
assertIsActionReady();
12461247
MapLocation nextLoc = this.getLocation().add(dir);
1248+
12471249
if (!this.robot.getType().isBabyRatType()) {
12481250
throw new GameActionException(CANT_DO_THAT, "Only rats can drop other rats!");
12491251
}

0 commit comments

Comments
 (0)