@@ -950,12 +950,14 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
950950 assertIsActionReady ();
951951 // Attack is limited to vision radius
952952 assertCanActLocation (loc , this .getType ().getVisionRadiusSquared ());
953+
953954 if (!this .getLocation ().isAdjacentTo (loc )) {
954955 throw new GameActionException (CANT_DO_THAT , "Rats can only attack adjacent squares!" );
955956 }
956957
957- if (!this .gameWorld .isPassable (loc ))
958+ if (!this .gameWorld .isPassable (loc )) {
958959 throw new GameActionException (CANT_DO_THAT , "Rats cannot attack squares with walls or dirt on them!" );
960+ }
959961
960962 if (this .gameWorld .getTeamInfo ().getCheese (this .getTeam ()) + this .getAllCheese () < cheeseConsumed ) {
961963 throw new GameActionException (CANT_DO_THAT , "Not enough cheese to bite!" );
@@ -964,13 +966,23 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
964966 if (this .getType () == UnitType .CAT ) {
965967 throw new GameActionException (CANT_DO_THAT , "Unit must be a baby rat or rat king to bite!" );
966968 }
969+
970+ if (cheeseConsumed < 0 ) {
971+ throw new GameActionException (CANT_DO_THAT , "Cheese consumed must be non-negative!" );
972+ }
973+
974+ if (this .gameWorld .getRobot (loc ) == null ) {
975+ throw new GameActionException (CANT_DO_THAT , "No robot to attack at the specified location!" );
976+ }
967977 }
968978
969979 private void assertCanAttackCat (MapLocation loc ) throws GameActionException {
970980 assertIsActionReady ();
971981 assertCanActLocation (loc , this .getType ().getVisionRadiusSquared ());
972- if (!this .gameWorld .isPassable (loc ))
982+
983+ if (!this .gameWorld .isPassable (loc )) {
973984 throw new GameActionException (CANT_DO_THAT , "Cats cannot attack squares with walls or dirt on them!" );
985+ }
974986 }
975987
976988 private void assertCanAttack (MapLocation loc , int cheeseConsumed ) throws GameActionException {
0 commit comments