Skip to content

Commit ca68587

Browse files
authored
Merge pull request #64 from battlecode/master
Release new bugfixes
2 parents aaafbce + 5153db7 commit ca68587

10 files changed

Lines changed: 63 additions & 44 deletions

File tree

client/src/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export const CLIENT_VERSION = '1.0.0'
1+
export const CLIENT_VERSION = '1.0.2'
22
export const SPEC_VERSION = '1'
33
export const BATTLECODE_YEAR: number = 2026
44
export const MAP_SIZE_RANGE = {

client/src/playback/Actions.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,12 +189,19 @@ 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-
target.carriedRobot = undefined
193-
src.carriedRobot = target.id
192+
if(src.carriedRobot === target.id) {
193+
// drop the target
194+
src.carriedRobot = undefined
195+
target.size = 1
196+
} else {
197+
// pick up the target
198+
src.carriedRobot = target.id
199+
target.carriedRobot = undefined
194200

195-
target.lastPos = { ...target.pos }
196-
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
197-
target.size = 0.6
201+
target.lastPos = { ...target.pos }
202+
target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
203+
target.size = 0.6
204+
}
198205
}
199206
draw(match: Match, ctx: CanvasRenderingContext2D): void {
200207
//target rat moves onto src rat, circle around carried group thing
@@ -655,16 +662,15 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
655662
draw(match: Match, ctx: CanvasRenderingContext2D): void {
656663
const body = match.currentRound.bodies.getById(this.robotId)
657664
const renderCoords = renderUtils.getRenderCoords(
658-
body.pos.x - 1 + body.size / 2,
659-
body.pos.y + body.size / 2,
665+
body.pos.x,
666+
body.pos.y,
660667
match.map.dimension,
661-
true
662668
)
663669
renderUtils.renderCenteredImageOrLoadingIndicator(
664670
ctx,
665671
getImageIfLoaded('robots/squeak.png'),
666672
renderCoords,
667-
1
673+
body.size
668674
)
669675
}
670676
},

client/src/playback/Map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ export class CurrentMap {
318318
if (ratTrap) {
319319
info.push('Rat Trap')
320320
}
321-
if (ratTrap) {
321+
if (catTrap) {
322322
info.push('Cat Trap')
323323
}
324324
if (cheese) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public class GameConstants {
8989
public static final double CHEESE_COOLDOWN_PENALTY = 0.01;
9090

9191
/** The amount of cheese the rat king consumes each round. */
92-
public static final int RAT_KING_CHEESE_CONSUMPTION = 3;
92+
public static final int RAT_KING_CHEESE_CONSUMPTION = 2;
9393

9494
/** The amount of health the rat king loses by not eating cheese. */
9595
public static final int RAT_KING_HEALTH_LOSS = 10;
@@ -101,7 +101,7 @@ public class GameConstants {
101101
public static final int SQ_CHEESE_SPAWN_RADIUS = 4;
102102

103103
/** How much cheese each mine spawns at once */
104-
public static final int CHEESE_SPAWN_AMOUNT = 5;
104+
public static final int CHEESE_SPAWN_AMOUNT = 20;
105105

106106
/** The number of rat kings a player starts with. */
107107
public static final int NUMBER_INITIAL_RAT_KINGS = 1;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public enum TrapType {
99
/**
1010
* Traps enemy rats
1111
*/
12-
RAT_TRAP(5, 50, 20, 25, 5, 0, 25, 2),
12+
RAT_TRAP(30, 50, 20, 25, 15, 0, 25, 2),
1313

1414
/**
1515
* Traps the cat

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public enum UnitType {
44
// health, size, speed, visionRadius, actionCooldown
55
BABY_RAT(100, 1, 20, 90, 10, 10, 17500),
66
RAT_KING(500, 3, 25, 360, 10, 40, 20000),
7-
CAT(10_000, 2, 30, 180, 15, 10, 17500);
7+
CAT(10_000, 2, 17, 180, 15, 20, 17500);
88

99
// amount of health robot initially starts with
1010
public final int health;

engine/src/main/battlecode/server/GameMaker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,9 @@ public void addDamageAction(int damagedRobotID, int damage) {
559559
});
560560
}
561561

562-
public void addRatNapAction(int grabberRobotID) {
562+
public void addRatNapAction(int nappedID) {
563563
applyToBuilders((builder) -> {
564-
int action = RatNap.createRatNap(builder, grabberRobotID);
564+
int action = RatNap.createRatNap(builder, nappedID);
565565
builder.addAction(action, Action.RatNap);
566566
});
567567
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -509,14 +509,15 @@ public void spawnCheese(CheeseMine mine) {
509509
// corresponding one
510510

511511
if (spawn) {
512-
addCheese(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
513-
addCheese(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
514512

515513
mine.setLastRound(this.currentRound);
516514
pairedMine.setLastRound(this.currentRound);
517515

518516
matchMaker.addCheeseSpawnAction(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT + this.getCheeseAmount(ogSpawnLoc));
519517
matchMaker.addCheeseSpawnAction(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT + this.getCheeseAmount(pairedSpawnLoc));
518+
519+
addCheese(ogSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
520+
addCheese(pairedSpawnLoc, GameConstants.CHEESE_SPAWN_AMOUNT);
520521
}
521522

522523
}

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

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,7 @@ public void bite(MapLocation loc, int cheeseConsumed) {
585585

586586
if (cheeseConsumed > 0) {
587587
this.addCheese(-cheeseConsumed);
588-
damage += (int) Math.ceil(Math.log(cheeseConsumed));
588+
damage += (int) Math.ceil(Math.sqrt(cheeseConsumed));
589589
}
590590

591591
targetRobot.addHealth(-damage);
@@ -617,7 +617,7 @@ public void scratch(MapLocation loc) {
617617
public void grabRobot(MapLocation loc) {
618618
this.robotBeingCarried = this.gameWorld.getRobot(loc);
619619
this.robotBeingCarried.getGrabbed(this); // Notify the grabbed robot that it has been picked up
620-
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
620+
this.gameWorld.getMatchMaker().addRatNapAction(this.robotBeingCarried.getID());
621621

622622
if (this.robotBeingCarried.getTeam() != this.getTeam()) {
623623
this.gameWorld.isCooperation = false;
@@ -650,11 +650,10 @@ private void swapGrabber() {
650650
this.gameWorld.removeRobot(dropLoc);
651651
this.gameWorld.addRobot(dropLoc, this);
652652

653-
this.gameWorld.getMatchMaker().addRatNapAction(this.ID);
653+
this.gameWorld.getMatchMaker().addRatNapAction(this.ID); // expand this rat
654+
this.gameWorld.getMatchMaker().addRatNapAction(grabber.ID); // shrink carrier rat
654655

655-
if (grabber.getTeam() != this.getTeam()) {
656-
grabber.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
657-
}
656+
grabber.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
658657
}
659658

660659
private void getGrabbed(InternalRobot grabber) {
@@ -668,9 +667,7 @@ private void getGrabbed(InternalRobot grabber) {
668667

669668
this.setInternalLocationOnly(grabber.getLocation());
670669

671-
if (grabber.getTeam() != this.getTeam()) {
672-
this.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
673-
}
670+
this.remainingCarriedDuration = GameConstants.MAX_CARRY_DURATION;
674671

675672
}
676673

@@ -688,18 +685,11 @@ private void getThrown(Direction dir) {
688685
this.thrownDir = dir;
689686
this.remainingThrowDuration = 4;
690687

691-
MapLocation nextLoc = this.getLocation().add(dir);
688+
this.setInternalLocationOnly(this.getLocation());
689+
this.gameWorld.removeRobot(this.getLocation());
692690

693-
// Cat feeding!
694-
if (this.gameWorld.getRobot(nextLoc) != null) { // there's a cat here
695-
this.addHealth(-this.getHealth()); // rat dies :(
696-
// put cat to sleep
697-
this.gameWorld.getRobot(nextLoc).sleepTimeRemaining = GameConstants.CAT_SLEEP_TIME;
698-
this.gameWorld.getMatchMaker().addCatFeedAction(this.getID());
699-
} else {
700-
this.setInternalLocationOnly(this.getLocation().add(dir));
701-
this.gameWorld.removeRobot(this.getLocation());
702-
}
691+
this.travelFlying(true);
692+
this.travelFlying(false);
703693
}
704694

705695
public void getDropped(MapLocation loc) {
@@ -714,6 +704,8 @@ public void getDropped(MapLocation loc) {
714704
this.grabbedByRobot = null;
715705
this.remainingCarriedDuration = 0;
716706
this.setInternalLocationOnly(loc);
707+
708+
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
717709

718710
if (this.getHealth() > 0)
719711
this.gameWorld.addRobot(this.getLocation(), this);
@@ -729,6 +721,8 @@ public void hitGround() {
729721
this.addHealth(-damage);
730722

731723
this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
724+
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
725+
732726

733727
if (this.health > 0) {
734728
this.gameWorld.addRobot(this.location, this);
@@ -760,6 +754,7 @@ public void hitTarget(boolean isSecondMove) {
760754
setActionCooldownTurns(this.actionCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
761755
setTurningCooldownTurns(this.turningCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
762756
this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
757+
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
763758

764759
this.gameWorld.getMatchMaker().addStunAction(this.ID, GameConstants.HIT_TARGET_COOLDOWN);
765760
}
@@ -1053,8 +1048,7 @@ public void processBeginningOfTurn() {
10531048
this.gameWorld.runCheeseMines();
10541049

10551050
// if rat is being carried
1056-
if (this.getType() == UnitType.BABY_RAT && this.isGrabbedByRobot()
1057-
&& this.getGrabbedByRobot().getTeam() != this.getTeam()) {
1051+
if (this.getType() == UnitType.BABY_RAT && this.isGrabbedByRobot()) {
10581052

10591053
// check if grabber has died
10601054
if (this.getGrabbedByRobot().getHealth() <= 0) {

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

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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,29 @@ 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+
}
986+
if (this.gameWorld.getRobot(loc) == null) {
987+
throw new GameActionException(CANT_DO_THAT, "No robot to attack at the specified location!");
988+
}
989+
if (this.gameWorld.getRobot(loc) != null && this.gameWorld.getRobot(loc).getID() == this.robot.getID()) {
990+
throw new GameActionException(CANT_DO_THAT, "Cannot attack self");
991+
}
974992
}
975993

976994
private void assertCanAttack(MapLocation loc, int cheeseConsumed) throws GameActionException {
@@ -1316,7 +1334,7 @@ public void assertCanCarryRat(MapLocation loc) throws GameActionException {
13161334
}
13171335

13181336
// adjacency
1319-
if (!loc.isAdjacentTo(this.getLocation())) {
1337+
if (!loc.isAdjacentTo(this.getLocation()) && !this.getLocation().equals(loc)) {
13201338
throw new GameActionException(CANT_DO_THAT, "A rat can only grab adjacent robots!");
13211339
}
13221340

0 commit comments

Comments
 (0)