@@ -426,7 +426,7 @@ public void removeDirt(MapLocation loc) throws GameActionException {
426426
427427 private void assertCanPickUpCheese (MapLocation loc ) throws GameActionException {
428428 assertIsRobotType (this .robot .getType ());
429- assertCanActLocation (loc , GameConstants .BUILD_DISTANCE_SQUARED );
429+ assertCanActLocation (loc , GameConstants .CHEESE_PICK_UP_RADIUS_SQUARED );
430430
431431 if (this .gameWorld .getCheeseAmount (loc ) <= 0 )
432432 throw new GameActionException (CANT_DO_THAT , "No cheese at this location!" );
@@ -840,13 +840,24 @@ public void move(Direction d) throws GameActionException {
840840 }
841841
842842 this .robot .addMovementCooldownTurns (d );
843-
844843 }
845844
846845 private void assertCanTurn () throws GameActionException {
847846 assertIsTurningReady ();
848847 }
849848
849+ private void assertCanTurn (Direction d ) throws GameActionException {
850+ assertIsTurningReady ();
851+
852+ if (d == null ) {
853+ throw new GameActionException (CANT_DO_THAT , "Direction to turn to is null!" );
854+ }
855+
856+ if (d == Direction .CENTER ) {
857+ throw new GameActionException (CANT_DO_THAT , "Cannot turn to CENTER direction!" );
858+ }
859+ }
860+
850861 @ Override
851862 public boolean canTurn () {
852863 try {
@@ -858,13 +869,21 @@ public boolean canTurn() {
858869 }
859870
860871 @ Override
861- public void turn (Direction d ) throws GameActionException {
862- assertCanTurn ();
863- if (d != Direction .CENTER ) {
864- this .robot .setDirection (d );
865- this .robot .addTurningCooldownTurns ();
872+ public boolean canTurn (Direction d ) {
873+ try {
874+ assertCanTurn (d );
875+ return true ;
876+ } catch (GameActionException e ) {
877+ return false ;
866878 }
879+ }
867880
881+ @ Override
882+ public void turn (Direction d ) throws GameActionException {
883+ assertCanTurn (d );
884+
885+ this .robot .setDirection (d );
886+ this .robot .addTurningCooldownTurns ();
868887 }
869888
870889 // ***********************************
@@ -1205,7 +1224,7 @@ public int readPersistentArray(int index) throws GameActionException {
12051224
12061225 private void assertCanTransferCheese (MapLocation loc , int amount ) throws GameActionException {
12071226 assertNotNull (loc );
1208- assertCanActLocation (loc , GameConstants .CHEESE_DROP_RADIUS_SQUARED );
1227+ assertCanActLocation (loc , GameConstants .CHEESE_TRANSFER_RADIUS_SQUARED );
12091228 assertIsActionReady ();
12101229 InternalRobot robot = this .gameWorld .getRobot (loc );
12111230 if (robot == null )
@@ -1354,6 +1373,7 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
13541373 }
13551374
13561375 InternalRobot targetRobot = this .gameWorld .getRobot (loc );
1376+
13571377 if (targetRobot == null ) {
13581378 throw new GameActionException (CANT_DO_THAT , "No robot at target location" );
13591379 }
@@ -1367,10 +1387,15 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
13671387 throw new GameActionException (CANT_DO_THAT , "Target robot is currently being thrown" );
13681388 }
13691389
1390+ if (targetRobot == this .robot ) {
1391+ throw new GameActionException (CANT_DO_THAT , "Robots cannot grab themselves" );
1392+ }
1393+
13701394 // Allow grabbing if the target is facing away (cannot sense this robot), or
13711395 // the target is allied, or the target is weaker (health comparison w/
13721396 // threshold)
13731397 boolean canGrab = false ;
1398+
13741399 if (!targetRobot .canSenseLocation (this .getLocation ())) {
13751400 canGrab = true ;
13761401 } else if (this .robot .getTeam () == targetRobot .getTeam ()) {
0 commit comments