@@ -230,11 +230,13 @@ private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws
230230 // }
231231
232232 private void assertCanPlaceDirt (MapLocation loc ) throws GameActionException {
233+ UnitType myType = this .robot .getType ();
234+
233235 assertIsActionReady ();
234- assertIsRobotType (this . robot . getType () );
235- // Use unit action radius as the allowed range for the action
236- assertCanActLocation ( loc , GameConstants .BUILD_DISTANCE_SQUARED );
237- assertIsActionReady ( );
236+ assertIsRobotType (myType );
237+ assertCanActLocation ( loc , myType == UnitType . RAT_KING
238+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
239+ : GameConstants . BUILD_DISTANCE_SQUARED );
238240
239241 // state checks :
240242 if (this .gameWorld .getTeamInfo ().getDirt (this .robot .getTeam ()) <= 0 )
@@ -308,10 +310,13 @@ private void assertCanRemoveRatTrap(MapLocation loc) throws GameActionException
308310 }
309311
310312 private void assertCanPlaceTrap (MapLocation loc , TrapType trapType ) throws GameActionException {
311- assertIsRobotType (this .robot .getType ());
312- assertIsActionReady ();
313- assertCanActLocation (loc , GameConstants .BUILD_DISTANCE_SQUARED );
313+ UnitType myType = this .robot .getType ();
314+
314315 assertIsActionReady ();
316+ assertIsRobotType (myType );
317+ assertCanActLocation (loc , myType == UnitType .RAT_KING
318+ ? GameConstants .RAT_KING_BUILD_DISTANCE_SQUARED
319+ : GameConstants .BUILD_DISTANCE_SQUARED );
315320
316321 if (trapType == TrapType .CAT_TRAP && !this .gameWorld .isCooperation )
317322 throw new GameActionException (CANT_DO_THAT , "Can't place new cat traps in backstabbing mode!" );
@@ -965,8 +970,11 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
965970 assertCanActLocation (loc , myType .getVisionRadiusSquared ());
966971
967972 MapLocation myLoc = this .getLocation ();
973+ int distSq = myLoc .distanceSquaredTo (loc );
968974
969- if (!myLoc .isAdjacentTo (loc ) && !(myType .isRatKingType () && myLoc .distanceSquaredTo (loc ) <= GameConstants .RAT_KING_ATTACK_DISTANCE_SQUARED )) {
975+ if (distSq == 0 || distSq > (myType == UnitType .RAT_KING
976+ ? GameConstants .RAT_KING_ATTACK_DISTANCE_SQUARED
977+ : GameConstants .ATTACK_DISTANCE_SQUARED )) {
970978 throw new GameActionException (CANT_DO_THAT , "Rats can only attack adjacent squares!" );
971979 }
972980
@@ -1081,8 +1089,16 @@ public void assertCanBecomeRatKing() throws GameActionException {
10811089 throw new GameActionException (CANT_DO_THAT , "Not enough cheese to upgrade to a rat king" );
10821090 }
10831091
1084- if (teamInfo .getNumRatKings (this .robot .getTeam ()) >= GameConstants .MAX_NUMBER_OF_RAT_KINGS ){
1085- throw new GameActionException (CANT_DO_THAT , "Cannot have more than " +GameConstants .MAX_NUMBER_OF_RAT_KINGS + "rat kings per team!" );
1092+ int numRatKings = teamInfo .getNumRatKings (this .robot .getTeam ());
1093+
1094+ if (numRatKings >= GameConstants .MAX_NUMBER_OF_RAT_KINGS ) {
1095+ throw new GameActionException (CANT_DO_THAT , "Cannot have more than " + GameConstants .MAX_NUMBER_OF_RAT_KINGS + " rat kings per team!" );
1096+ }
1097+
1098+ if (numRatKings >= GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF && this .gameWorld .getCurrentRound () > GameConstants .RAT_KING_CUTOFF_ROUND ) {
1099+ throw new GameActionException (CANT_DO_THAT ,
1100+ "Cannot make a new rat king when your team has at least " + GameConstants .MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF
1101+ + " rat kings after round " + GameConstants .RAT_KING_CUTOFF_ROUND + "!" );
10861102 }
10871103
10881104 int numAllyRats = 0 ;
0 commit comments