@@ -68,7 +68,7 @@ private InternalRobot getRobotByID(int id) {
6868 }
6969
7070 // private int locationToInt(MapLocation loc) {
71- // return this.gameWorld.locationToIndex(loc);
71+ // return this.gameWorld.locationToIndex(loc);
7272 // }
7373
7474 private MapInfo getMapInfo (MapLocation loc ) throws GameActionException {
@@ -213,23 +213,25 @@ private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws
213213 ? (getLocation ().bottomLeftDistanceSquaredTo (loc ))
214214 : (getLocation ().distanceSquaredTo (loc ));
215215
216- // float addDistance = (float) Math.ceil((this.getType().size / (2.0) + Math.sqrt((double) maxRadiusSquared))
217- // * (this.getType().size / 2.0 + Math.sqrt((double) maxRadiusSquared)));
216+ // float addDistance = (float) Math.ceil((this.getType().size / (2.0) +
217+ // Math.sqrt((double) maxRadiusSquared))
218+ // * (this.getType().size / 2.0 + Math.sqrt((double) maxRadiusSquared)));
218219 float addDistance = maxRadiusSquared ;
219220
220221 if (distance > addDistance )
221222 throw new GameActionException (OUT_OF_RANGE ,
222223 "Target location not within action range" );
223224 }
224225
225- // private void assertCanActOffCenterLocation(MapLocation loc, int maxRadiusSquared) throws GameActionException {
226- // assertNotNull(loc);
227- // if (getLocation().bottomLeftDistanceSquaredTo(loc) > maxRadiusSquared)
228- // throw new GameActionException(OUT_OF_RANGE,
229- // "Target location not within action range");
230- // if (!this.gameWorld.getGameMap().onTheMap(loc))
231- // throw new GameActionException(CANT_SENSE_THAT,
232- // "Target location is not on the map");
226+ // private void assertCanActOffCenterLocation(MapLocation loc, int
227+ // maxRadiusSquared) throws GameActionException {
228+ // assertNotNull(loc);
229+ // if (getLocation().bottomLeftDistanceSquaredTo(loc) > maxRadiusSquared)
230+ // throw new GameActionException(OUT_OF_RANGE,
231+ // "Target location not within action range");
232+ // if (!this.gameWorld.getGameMap().onTheMap(loc))
233+ // throw new GameActionException(CANT_SENSE_THAT,
234+ // "Target location is not on the map");
233235 // }
234236
235237 private void assertCanPlaceDirt (MapLocation loc ) throws GameActionException {
@@ -238,8 +240,8 @@ private void assertCanPlaceDirt(MapLocation loc) throws GameActionException {
238240 assertIsActionReady ();
239241 assertIsRobotType (myType );
240242 assertCanActLocation (loc , myType == UnitType .RAT_KING
241- ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
242- : GameConstants .BUILD_DISTANCE_SQUARED );
243+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
244+ : GameConstants .BUILD_DISTANCE_SQUARED );
243245
244246 // state checks :
245247 if (this .gameWorld .getTeamInfo ().getDirt (this .robot .getTeam ()) <= 0 )
@@ -262,8 +264,8 @@ private void assertCanRemoveDirt(MapLocation loc) throws GameActionException {
262264 assertIsActionReady ();
263265 assertIsRobotType (myType );
264266 assertCanActLocation (loc , myType == UnitType .RAT_KING
265- ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
266- : GameConstants .BUILD_DISTANCE_SQUARED );
267+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
268+ : GameConstants .BUILD_DISTANCE_SQUARED );
267269
268270 if ((this .robot .getType ().isBabyRatType ()
269271 || this .robot .getType ().isRatKingType ()) && (this .getAllCheese () < GameConstants .DIG_DIRT_CHEESE_COST ))
@@ -311,8 +313,8 @@ private void assertCanRemoveRatTrap(MapLocation loc) throws GameActionException
311313
312314 assertIsRobotType (myType );
313315 assertCanActLocation (loc , myType == UnitType .RAT_KING
314- ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
315- : GameConstants .BUILD_DISTANCE_SQUARED );
316+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
317+ : GameConstants .BUILD_DISTANCE_SQUARED );
316318
317319 if (!this .gameWorld .hasRatTrap (loc , myTeam )) {
318320 throw new GameActionException (CANT_DO_THAT , "No rat trap to remove at that location!" );
@@ -325,8 +327,8 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
325327 assertIsActionReady ();
326328 assertIsRobotType (myType );
327329 assertCanActLocation (loc , myType == UnitType .RAT_KING
328- ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
329- : GameConstants .BUILD_DISTANCE_SQUARED );
330+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
331+ : GameConstants .BUILD_DISTANCE_SQUARED );
330332
331333 if (trapType == TrapType .CAT_TRAP && !this .gameWorld .isCooperation )
332334 throw new GameActionException (CANT_DO_THAT , "Can't place new cat traps in backstabbing mode!" );
@@ -351,8 +353,8 @@ private void assertCanRemoveCatTrap(MapLocation loc) throws GameActionException
351353
352354 assertIsRobotType (myType );
353355 assertCanActLocation (loc , myType == UnitType .RAT_KING
354- ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
355- : GameConstants .BUILD_DISTANCE_SQUARED );
356+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
357+ : GameConstants .BUILD_DISTANCE_SQUARED );
356358
357359 if (!this .gameWorld .hasCatTrap (loc , this .getTeam ())) {
358360 throw new GameActionException (CANT_DO_THAT , "No cat trap to remove at that location!" );
@@ -555,7 +557,8 @@ public RobotInfo[] senseNearbyRobots(MapLocation center, int radiusSquared, Team
555557 int actualRadiusSquared = radiusSquared == -1 ? this .robot .getVisionRadiusSquared ()
556558 : Math .min (radiusSquared , this .robot .getVisionRadiusSquared ());
557559
558- InternalRobot [] allSensedRobots = gameWorld .getAllRobotsWithinRadiusSquared (center , actualRadiusSquared , team , this .robot .getChirality ());
560+ InternalRobot [] allSensedRobots = gameWorld .getAllRobotsWithinRadiusSquared (center , actualRadiusSquared , team ,
561+ this .robot .getChirality ());
559562 List <RobotInfo > validSensedRobots = new ArrayList <>();
560563 HashSet <Integer > uniqueRobotIds = new HashSet <>();
561564 for (InternalRobot sensedRobot : allSensedRobots ) {
@@ -566,13 +569,14 @@ public RobotInfo[] senseNearbyRobots(MapLocation center, int radiusSquared, Team
566569 continue ;
567570 // check if can sense in vision cone (restricted radius)
568571 boolean canSensePartOfRobot = false ;
569- for (MapLocation robotpart : sensedRobot .getAllPartLocations ()){
570- canSensePartOfRobot = canSensePartOfRobot || (canSenseLocation (robotpart ) && center .isWithinDistanceSquared (robotpart , actualRadiusSquared ));
572+ for (MapLocation robotpart : sensedRobot .getAllPartLocations ()) {
573+ canSensePartOfRobot = canSensePartOfRobot || (canSenseLocation (robotpart )
574+ && center .isWithinDistanceSquared (robotpart , actualRadiusSquared ));
571575 }
572576
573577 if (!canSensePartOfRobot )
574578 continue ;
575-
579+
576580 // check if right team
577581 if (team != null && sensedRobot .getTeam () != team )
578582 continue ;
@@ -624,9 +628,9 @@ public MapInfo[] senseNearbyMapInfos(MapLocation center, int radiusSquared) thro
624628 : Math .min (radiusSquared , this .getType ().visionConeRadiusSquared );
625629 MapLocation [] allSensedLocs = gameWorld .getAllLocationsWithinRadiusSquared (center ,
626630 actualRadiusSquared , this .robot .getChirality ()); // expand slightly
627- // to allow
628- // off-center
629- // sensing
631+ // to allow
632+ // off-center
633+ // sensing
630634 List <MapInfo > validSensedMapInfo = new ArrayList <>();
631635 for (MapLocation mapLoc : allSensedLocs ) {
632636 // Can't actually sense location
@@ -652,7 +656,8 @@ public MapLocation[] getAllLocationsWithinRadiusSquared(MapLocation center, int
652656 int actualRadiusSquared = radiusSquared == -1 ? this .robot .getVisionRadiusSquared ()
653657 : Math .min (radiusSquared , this .robot .getVisionRadiusSquared ());
654658 MapLocation [] possibleLocs = this .gameWorld .getAllLocationsWithinConeRadiusSquared (center ,
655- this .robot .getDirection (), this .robot .getVisionConeAngle (), actualRadiusSquared , this .robot .getChirality ());
659+ this .robot .getDirection (), this .robot .getVisionConeAngle (), actualRadiusSquared ,
660+ this .robot .getChirality ());
656661 List <MapLocation > visibleLocs = Arrays .asList (possibleLocs ).stream ().filter (x -> canSenseLocation (x ))
657662 .collect (Collectors .toList ());
658663 return visibleLocs .toArray (new MapLocation [visibleLocs .size ()]);
@@ -771,9 +776,9 @@ private void assertCanMove(Direction d) throws GameActionException {
771776 InternalRobot occupyingRobot = this .gameWorld .getRobot (loc );
772777
773778 if ((occupyingRobot != null ) && (occupyingRobot .getID () != this .robot .getID ())
774- && !(occupyingRobot .getType ().isBabyRatType () && this .getType ().isCatType ())) {
779+ && !(occupyingRobot .getType ().isBabyRatType () && this .getType ().isCatType ())) {
775780 throw new GameActionException (CANT_MOVE_THERE ,
776- "Cannot move to an occupied location; " + loc + " is occupied by a different robot." );
781+ "Cannot move to an occupied location; " + loc + " is occupied by a different robot." );
777782 }
778783
779784 if (!this .gameWorld .isPassable (loc )) {
@@ -823,7 +828,7 @@ public void processTrapsAtLocation(MapLocation loc) {
823828 if (trap .getTeam () == this .robot .getTeam () || wrongTrapType ) {
824829 continue ;
825830 }
826-
831+
827832 this .gameWorld .triggerTrap (trap , robot );
828833
829834 }
@@ -991,15 +996,15 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
991996 int distSq = myLoc .distanceSquaredTo (loc );
992997
993998 if (distSq == 0 || distSq > (myType == UnitType .RAT_KING
994- ? GameConstants .RAT_KING_ATTACK_DISTANCE_SQUARED
995- : GameConstants .ATTACK_DISTANCE_SQUARED )) {
999+ ? GameConstants .RAT_KING_ATTACK_DISTANCE_SQUARED
1000+ : GameConstants .ATTACK_DISTANCE_SQUARED )) {
9961001 throw new GameActionException (CANT_DO_THAT , "Rats can only attack adjacent squares!" );
9971002 }
9981003
9991004 if (!this .gameWorld .isPassable (loc )) {
10001005 throw new GameActionException (CANT_DO_THAT , "Rats cannot attack squares with walls or dirt on them!" );
10011006 }
1002-
1007+
10031008 if (this .getAllCheese () < cheeseConsumed ) {
10041009 throw new GameActionException (CANT_DO_THAT , "Not enough cheese to bite!" );
10051010 }
@@ -1036,7 +1041,7 @@ private void assertCanAttackCat(MapLocation loc) throws GameActionException {
10361041 if (enemyRobot == null ) {
10371042 throw new GameActionException (CANT_DO_THAT , "No robot to attack at the specified location!" );
10381043 }
1039-
1044+
10401045 if (enemyRobot != null && enemyRobot .getTeam () == this .robot .getTeam ()) {
10411046 throw new GameActionException (CANT_DO_THAT , "Cannot attack another cat!" );
10421047 }
@@ -1110,12 +1115,15 @@ public void assertCanBecomeRatKing() throws GameActionException {
11101115 int numRatKings = teamInfo .getNumRatKings (this .robot .getTeam ());
11111116
11121117 if (numRatKings >= GameConstants .MAX_NUMBER_OF_RAT_KINGS ) {
1113- throw new GameActionException (CANT_DO_THAT , "Cannot have more than " + GameConstants .MAX_NUMBER_OF_RAT_KINGS + " rat kings per team!" );
1118+ throw new GameActionException (CANT_DO_THAT ,
1119+ "Cannot have more than " + GameConstants .MAX_NUMBER_OF_RAT_KINGS + " rat kings per team!" );
11141120 }
11151121
1116- if (numRatKings >= GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF && this .gameWorld .getCurrentRound () > GameConstants .RAT_KING_CUTOFF_ROUND ) {
1122+ if (numRatKings >= GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF
1123+ && this .gameWorld .getCurrentRound () > GameConstants .RAT_KING_CUTOFF_ROUND ) {
11171124 throw new GameActionException (CANT_DO_THAT ,
1118- "Cannot make a new rat king when your team has at least " + GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF
1125+ "Cannot make a new rat king when your team has at least "
1126+ + GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF
11191127 + " rat kings after round " + GameConstants .RAT_KING_CUTOFF_ROUND + "!" );
11201128 }
11211129
@@ -1131,7 +1139,8 @@ public void assertCanBecomeRatKing() throws GameActionException {
11311139
11321140 InternalRobot curRobot = this .gameWorld .getRobot (curLoc );
11331141
1134- if (curRobot != null && curRobot .getTeam () == this .robot .getTeam () && curRobot .getType () == UnitType .BABY_RAT ) {
1142+ if (curRobot != null && curRobot .getTeam () == this .robot .getTeam ()
1143+ && curRobot .getType () == UnitType .BABY_RAT ) {
11351144 numAllyRats += 1 ;
11361145 }
11371146
@@ -1204,7 +1213,6 @@ public void becomeRatKing() throws GameActionException {
12041213 this .robot .addCheese (-this .robot .getCheese ());
12051214 this .robot .becomeRatKing (health );
12061215
1207-
12081216 for (Direction d : Direction .allDirections ()) {
12091217 if (d != Direction .CENTER ) {
12101218 MapLocation newLoc = this .adjacentLocation (d );
@@ -1222,7 +1230,7 @@ public void becomeRatKing() throws GameActionException {
12221230
12231231 @ Override
12241232 public boolean squeak (int messageContent ) {
1225- if (this .robot .getSentMessagesCount () >= GameConstants .MAX_MESSAGES_SENT_ROBOT )
1233+ if (this .robot .getSentMessagesCount () >= GameConstants .MAX_MESSAGES_SENT_ROBOT )
12261234 return false ;
12271235 Message message = new Message (messageContent , this .robot .getID (), this .gameWorld .getCurrentRound (),
12281236 this .getLocation ());
@@ -1341,14 +1349,15 @@ public void assertCanThrowRat(Direction dir) throws GameActionException {
13411349 throw new GameActionException (CANT_DO_THAT , "Cannot throw outside of map!" );
13421350 }
13431351 if (!this .gameWorld .isPassable (nextLoc ) || (this .gameWorld .getRobot (nextLoc ) != null )) {
1344- throw new GameActionException (CANT_DO_THAT , "There must be at least 1 empty space in front the throwing rat!" );
1352+ throw new GameActionException (CANT_DO_THAT ,
1353+ "There must be at least 1 empty space in front the throwing rat!" );
13451354 }
13461355 }
13471356
13481357 public void assertCanDropRat (Direction dir ) throws GameActionException {
13491358 assertIsActionReady ();
13501359 MapLocation nextLoc = this .getLocation ().add (dir );
1351-
1360+
13521361 if (!this .robot .getType ().isBabyRatType ()) {
13531362 throw new GameActionException (CANT_DO_THAT , "Only rats can drop other rats!" );
13541363 }
@@ -1391,6 +1400,7 @@ public boolean canDropRat(Direction dir) {
13911400 public void dropRat (Direction dir ) throws GameActionException {
13921401 assertCanDropRat (dir );
13931402 this .robot .dropRobot (dir );
1403+ this .robot .addActionCooldownTurns (GameConstants .THROW_RAT_COOLDOWN );
13941404 }
13951405
13961406 public void assertCanCarryRat (MapLocation loc ) throws GameActionException {
@@ -1403,7 +1413,7 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
14031413 throw new GameActionException (CANT_DO_THAT , "Unit must be a rat to grab other rats" );
14041414 } else if (this .robot .isCarryingRobot ()) {
14051415 throw new GameActionException (CANT_DO_THAT , "Already carrying a rat" );
1406- }
1416+ }
14071417 // Must be a rat-type
14081418 if (!this .robot .getType ().isBabyRatType ()) {
14091419 throw new GameActionException (CANT_DO_THAT , "Only rats can grab other rats!" );
@@ -1448,8 +1458,10 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
14481458 throw new GameActionException (CANT_DO_THAT , "Robots cannot grab themselves" );
14491459 }
14501460
1451- if (targetRobot .getTeam () != this .robot .getTeam () && targetRobot .getLastGrabberId () == this .robot .getID () && targetRobot .getTurnsSinceThrownOrDropped () < GameConstants .SAME_ROBOT_CARRY_COOLDOWN_TURNS ) {
1452- throw new GameActionException (CANT_DO_THAT , "Target robot (on the enemy team) was recently carried by this robot" );
1461+ if (targetRobot .getTeam () != this .robot .getTeam () && targetRobot .getLastGrabberId () == this .robot .getID ()
1462+ && targetRobot .getTurnsSinceThrownOrDropped () < GameConstants .SAME_ROBOT_CARRY_COOLDOWN_TURNS ) {
1463+ throw new GameActionException (CANT_DO_THAT ,
1464+ "Target robot (on the enemy team) was recently carried by this robot" );
14531465 }
14541466
14551467 // Allow grabbing if the target is facing away (cannot sense this robot), or
@@ -1484,6 +1496,7 @@ public boolean canCarryRat(MapLocation loc) {
14841496 public void carryRat (MapLocation loc ) throws GameActionException {
14851497 assertCanCarryRat (loc );
14861498 this .robot .grabRobot (loc );
1499+ this .robot .addActionCooldownTurns (GameConstants .THROW_RAT_COOLDOWN );
14871500 }
14881501
14891502 @ Override
0 commit comments