Skip to content

Commit 9de9899

Browse files
committed
Merge branch 'master' into engine-release
2 parents ca68587 + 05b3193 commit 9de9899

8 files changed

Lines changed: 56 additions & 19 deletions

File tree

client/src/playback/Actions.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,17 +189,18 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
189189
const src = round.bodies.getById(this.robotId)
190190
const target = round.bodies.getById(this.actionData.id()) // rat getting napped
191191

192-
if(src.carriedRobot === target.id) {
192+
if (target.beingCarried) {
193193
// drop the target
194-
src.carriedRobot = undefined
195194
target.size = 1
195+
target.beingCarried = false
196196
} else {
197197
// pick up the target
198198
src.carriedRobot = target.id
199199
target.carriedRobot = undefined
200+
target.beingCarried = true
200201

201-
target.lastPos = { ...target.pos }
202-
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
202+
// target.lastPos = { ...target.pos }
203+
// target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
203204
target.size = 0.6
204205
}
205206
}

client/src/playback/Bodies.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export class Body {
364364
public actionCooldown: number = 0
365365
public turningCooldown: number = 0
366366
public carriedRobot: number | undefined = undefined // id of carried robot
367+
public beingCarried: boolean = false
367368
public bytecodesUsed: number = 0
368369
public cheese: number = 0
369370

engine/src/main/battlecode/common/GameConstants.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ public class GameConstants {
106106
/** The number of rat kings a player starts with. */
107107
public static final int NUMBER_INITIAL_RAT_KINGS = 1;
108108

109-
/**
110-
* The maximum distance for transferring cheese to an allied rat king or
111-
* dropping it on the ground
112-
*/
113-
public static final int CHEESE_DROP_RADIUS_SQUARED = 9;
109+
/** The maximum distance for transferring cheese to an allied rat king */
110+
public static final int CHEESE_TRANSFER_RADIUS_SQUARED = 9;
111+
112+
/** The maximum distance for picking up cheese on the map */
113+
public static final int CHEESE_PICK_UP_RADIUS_SQUARED = 2;
114114

115115
/** The maximum distance from a rat king for building robots */
116116
public static final int BUILD_ROBOT_RADIUS_SQUARED = 4;

engine/src/main/battlecode/common/MapInfo.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ public boolean isWall() {
5050
}
5151

5252
/**
53-
* Returns if this square is a wall.
53+
* Returns if this square is a dirt.
5454
*
55-
* @return whether this square is a wall
55+
* @return whether this square is dirt
5656
*
5757
* @battlecode.doc.costlymethod
5858
*/

engine/src/main/battlecode/common/RobotController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,15 @@ public interface RobotController {
586586
*/
587587
boolean canTurn();
588588

589+
/**
590+
* Checks whether this robot can turn to the specified direction.
591+
* Effectively just canTurn() with an extra check that d is not null.
592+
*
593+
* @param d the direction to turn to
594+
* @throws GameActionException
595+
*/
596+
boolean canTurn(Direction d);
597+
589598
/**
590599
* Turns to the specified direction
591600
*

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,7 @@ public void scratch(MapLocation loc) {
616616

617617
public void grabRobot(MapLocation loc) {
618618
this.robotBeingCarried = this.gameWorld.getRobot(loc);
619+
System.out.println("Robot " + this.ID + " grabbed robot " + this.robotBeingCarried);
619620
this.robotBeingCarried.getGrabbed(this); // Notify the grabbed robot that it has been picked up
620621
this.gameWorld.getMatchMaker().addRatNapAction(this.robotBeingCarried.getID());
621622

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

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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()) {

specs/specs.pdf

4.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)