Skip to content

Commit 5c42ca2

Browse files
2 parents c5ffbc2 + 54f487b commit 5c42ca2

8 files changed

Lines changed: 113 additions & 90 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Note, Competitors
66
This is the development repo! You most likely won't need anything in here; do not clone this.
7-
Instead, follow the instructions [here](https://play.battlecode.org/bc26java/quick_start) to get started.
7+
Instead, follow the instructions [here](https://play.battlecode.org/bc26/quick_start) to get started.
88

99
## Repository Structure
1010

client/src/playback/Actions.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,13 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
195195
if (target.beingCarried) {
196196
// drop the target
197197
// const carrier = round.bodies.getById(target.carrierRobot!)
198-
if(target.carrierRobot !== undefined) {
198+
if(target.carrierRobot !== undefined && round.bodies.hasId(target.carrierRobot)) {
199199
const carrier = round.bodies.getById(target.carrierRobot)
200200
carrier.carriedRobot = undefined
201201
}
202-
target.size = 1
203202
target.beingCarried = false
204203
target.carrierRobot = undefined
204+
target.size = 1
205205
} else {
206206
// pick up the target
207207
src.carriedRobot = target.id
@@ -210,8 +210,8 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
210210
target.beingCarried = true
211211

212212
target.lastPos = { ...target.pos }
213-
// target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
214213
target.size = 0.6
214+
// target.pos = { x: src.pos.x + RatNapAction.OFFSET.x, y: src.pos.y + RatNapAction.OFFSET.y }
215215
}
216216
}
217217
draw(match: Match, ctx: CanvasRenderingContext2D): void {
@@ -576,7 +576,6 @@ export const ACTION_DEFINITIONS: Record<schema.Action, typeof Action<ActionUnion
576576
carrier.carriedRobot = undefined
577577
}
578578
body.carrierRobot = undefined
579-
body.beingCarried = false
580579
body.size = 1
581580
// body.pos = { ...endLoc }
582581
}

client/src/playback/Bodies.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ export class Body {
432432
}
433433

434434
public draw(match: Match, ctx: CanvasRenderingContext2D): void {
435-
const OFFSET = { x: .35, y: 0 } // to center the rat on the tile
436-
const ratnapped = this.robotType === schema.RobotType.RAT && this.beingCarried
437-
438435
const pos = this.getInterpolatedCoords(match)
439436

440437
const renderCoords = renderUtils.getRenderCoords(pos.x, pos.y, match.currentRound.map.staticMap.dimension)

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ public class GameConstants {
133133
/** The maximum distance from a robot for building traps or dirt */
134134
public static final int BUILD_DISTANCE_SQUARED = 2;
135135

136+
/**
137+
* The maximum distance squared a rat king can attack, measured from the king's center.
138+
* All rats (including rat kings) can only attack adjacent squares,
139+
* and the rat king is 3x3, so this is 8.
140+
*/
141+
public static final int RAT_KING_ATTACK_DISTANCE_SQUARED = 8;
142+
136143
/** The maximum number of rounds a message will exist for */
137144
public static final int MESSAGE_ROUND_DURATION = 5;
138145

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public final boolean isWithinDistanceSquared(MapLocation location, int distanceS
168168
* @param facingDir the direction robot is facing (if Center, ignores
169169
* theta argument and uses a 360 degree vision cone)
170170
* @param theta the angle of the vision cone in degrees
171-
* @param useTopRight true if the top right coordinate of this location (not
171+
* @param useBottomLeft true if the bottom left coordinate of this location (not
172172
* the "location" argument) should be used (for 2x2
173173
* robots)
174174
* @return true if the given location is within distanceSquared to this one;
@@ -177,7 +177,7 @@ public final boolean isWithinDistanceSquared(MapLocation location, int distanceS
177177
* @battlecode.doc.costlymethod
178178
*/
179179
public final boolean isWithinDistanceSquared(MapLocation location, int distanceSquared, Direction facingDir,
180-
double theta, boolean useTopRight) {
180+
double theta, boolean useBottomLeft) {
181181

182182
// prevent division by 0 error
183183
if (this.equals(location)) {
@@ -186,12 +186,12 @@ public final boolean isWithinDistanceSquared(MapLocation location, int distanceS
186186

187187
double adjustment = 1e-3;
188188

189-
boolean isValidDistance = useTopRight ? this.bottomLeftDistanceSquaredTo(location) <= distanceSquared
189+
boolean isValidDistance = useBottomLeft ? this.bottomLeftDistanceSquaredTo(location) <= distanceSquared
190190
: this.distanceSquaredTo(location) <= distanceSquared;
191191

192192
// calculate angle (degrees) between facingDir and direction to location
193-
double dx = location.x - (useTopRight ? (this.x + 0.5) : this.x);
194-
double dy = location.y - (useTopRight ? (this.y + 0.5) : this.y);
193+
double dx = location.x - (useBottomLeft ? (this.x + 0.5) : this.x);
194+
double dy = location.y - (useBottomLeft ? (this.y + 0.5) : this.y);
195195

196196
boolean isValidAngle;
197197
if (facingDir == Direction.CENTER) { //

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public class GameWorld {
4444
private final TeamInfo teamInfo;
4545
private final ObjectInfo objectInfo;
4646
private boolean hasRunCheeseMinesThisRound; // whether we've run the cheese mines yet
47-
47+
private HashSet<Integer> hasTraveledIDs; // ids of robots that have traveled this ronud
48+
4849
private int[] currentNumberUnits = { 0, 0 };
4950

5051
private Map<Team, ProfilerCollection> profilerCollections;
@@ -172,7 +173,8 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match
172173

173174
// Write match header at beginning of match
174175
this.matchMaker.makeMatchHeader(this.gameMap);
175-
176+
177+
this. hasTraveledIDs = new HashSet<>();
176178
this.allCheeseMinesByLoc = gm.getCheeseMineArray();
177179
this.cheeseMines = new ArrayList<CheeseMine>();
178180
this.cheeseMineLocs = new CheeseMine[numSquares];
@@ -746,6 +748,14 @@ public MapLocation[] getAllLocationsWithinConeRadiusSquaredWithoutMap(MapLocatio
746748
return returnLocations.toArray(new MapLocation[returnLocations.size()]);
747749
}
748750

751+
752+
public void addHasTraveledRobot(int id){
753+
this.hasTraveledIDs.add(id);
754+
}
755+
public boolean getHasTraveledRobot(int id){
756+
return this.hasTraveledIDs.contains(id);
757+
}
758+
749759
/**
750760
* @return all of the locations on the grid
751761
*/
@@ -877,11 +887,11 @@ public boolean setWinnerIfMorePoints() {
877887

878888
for (Team team : List.of(Team.A, Team.B)) {
879889

880-
float proportion_rat_kings = total_num_rat_kings != 0 ? teamInfo.getNumRatKings(team) / total_num_rat_kings : 0;
881-
float proportion_cheese_transferred = total_amount_cheese_transferred != 0 ? teamInfo.getCheeseTransferred(team) / total_amount_cheese_transferred : 0;
882-
float proportion_cat_damage = total_amount_cat_damage != 0 ? teamInfo.getDamageToCats(team) / total_amount_cat_damage : 0;
890+
float proportion_rat_kings = total_num_rat_kings != 0 ? (float)teamInfo.getNumRatKings(team) / total_num_rat_kings : 0.0f;
891+
float proportion_cheese_transferred = total_amount_cheese_transferred != 0 ? (float)teamInfo.getCheeseTransferred(team) / total_amount_cheese_transferred : 0.0f;
892+
float proportion_cat_damage = total_amount_cat_damage != 0 ? (float)teamInfo.getDamageToCats(team) / total_amount_cat_damage : 0.0f;
883893

884-
int points = (int) (cat_weight * 100 * (proportion_cat_damage) + king_weight * 100 * proportion_rat_kings
894+
int points = (int) (cat_weight * 100 * proportion_cat_damage + king_weight * 100 * proportion_rat_kings
885895
+ cheese_transfer_weight * 100 * proportion_cheese_transferred);
886896
this.teamInfo.addPoints(team, points);
887897
teamPoints.add(points);
@@ -958,6 +968,7 @@ public void processEndOfRound() {
958968
this.matchMaker.addTeamInfo(t, this.teamInfo.getCheeseTransferred(t), this.teamInfo.getDamageToCats(t), this.teamInfo.getNumRatKings(t), this.teamInfo.getNumBabyRats(t), this.teamInfo.getDirt(t), this.getTrapCount(TrapType.RAT_TRAP, t), this.getTrapCount(TrapType.CAT_TRAP, t));
959969
}
960970
this.teamInfo.processEndOfRound();
971+
hasTraveledIDs.clear();
961972

962973
this.getMatchMaker().endRound();
963974

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

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -588,11 +588,12 @@ public void bite(MapLocation loc, int cheeseConsumed) {
588588
damage += (int) Math.ceil(Math.sqrt(cheeseConsumed));
589589
}
590590

591+
this.gameWorld.getMatchMaker().addBiteAction(targetRobot.ID);
592+
591593
targetRobot.addHealth(-damage);
592594
if (targetRobot.getType() == UnitType.CAT) {
593595
this.gameWorld.getTeamInfo().addDamageToCats(team, damage);
594596
}
595-
this.gameWorld.getMatchMaker().addBiteAction(this.getID());
596597

597598
if (targetRobot.getType() != UnitType.CAT) {
598599
this.gameWorld.isCooperation = false;
@@ -616,7 +617,6 @@ public void scratch(MapLocation loc) {
616617

617618
public void grabRobot(MapLocation loc) {
618619
this.robotBeingCarried = this.gameWorld.getRobot(loc);
619-
System.out.println("Robot " + this.ID + " grabbed robot " + this.robotBeingCarried);
620620
this.robotBeingCarried.getGrabbed(this); // Notify the grabbed robot that it has been picked up
621621
this.gameWorld.getMatchMaker().addRatNapAction(this.robotBeingCarried.getID());
622622

@@ -673,7 +673,12 @@ private void getGrabbed(InternalRobot grabber) {
673673
}
674674

675675
public void throwRobot() {
676+
this.gameWorld.getMatchMaker().endTurn(this.ID, this.health, this.cheeseAmount, this.movementCooldownTurns,
677+
this.actionCooldownTurns, this.turningCooldownTurns, this.bytecodesUsed, this.location, this.dir, this.gameWorld.isCooperation);
676678
this.robotBeingCarried.getThrown(this.dir);
679+
this.gameWorld.getMatchMaker().endTurn(this.robotBeingCarried.ID, this.robotBeingCarried.health, this.robotBeingCarried.cheeseAmount, this.robotBeingCarried.movementCooldownTurns,
680+
this.robotBeingCarried.actionCooldownTurns, this.robotBeingCarried.turningCooldownTurns, this.robotBeingCarried.bytecodesUsed, this.robotBeingCarried.location, this.robotBeingCarried.dir, this.gameWorld.isCooperation);
681+
this.gameWorld.addHasTraveledRobot(this.robotBeingCarried.getID());
677682
this.gameWorld.getMatchMaker().addThrowAction(this.robotBeingCarried.getID(),
678683
this.getLocation().add(this.dir));
679684
this.robotBeingCarried = null;
@@ -687,7 +692,6 @@ private void getThrown(Direction dir) {
687692
this.remainingThrowDuration = 4;
688693

689694
this.setInternalLocationOnly(this.getLocation());
690-
this.gameWorld.removeRobot(this.getLocation());
691695

692696
this.travelFlying(true);
693697
this.travelFlying(false);
@@ -708,8 +712,10 @@ public void getDropped(MapLocation loc) {
708712

709713
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
710714

711-
if (this.getHealth() > 0)
715+
if (this.getHealth() > 0){
712716
this.gameWorld.addRobot(this.getLocation(), this);
717+
this.controller.processTrapsAtLocation(this.location);
718+
}
713719
else
714720
this.gameWorld.destroyRobot(this.getID());
715721
}
@@ -727,6 +733,10 @@ public void hitGround() {
727733

728734
if (this.health > 0) {
729735
this.gameWorld.addRobot(this.location, this);
736+
this.controller.processTrapsAtLocation(this.location);
737+
}
738+
else{
739+
this.gameWorld.destroyRobot(this.getID());
730740
}
731741

732742
setMovementCooldownTurns(this.movementCooldownTurns + GameConstants.HIT_GROUND_COOLDOWN);
@@ -748,9 +758,14 @@ public void hitTarget(boolean isSecondMove) {
748758
this.remainingThrowDuration = 0;
749759

750760
this.addHealth(-damage);
751-
if (this.health > 0){
761+
if (this.health > 0) {
752762
this.gameWorld.addRobot(this.location, this);
763+
this.controller.processTrapsAtLocation(this.location);
753764
}
765+
else{
766+
this.gameWorld.destroyRobot(this.getID());
767+
}
768+
754769
setMovementCooldownTurns(this.movementCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
755770
setActionCooldownTurns(this.actionCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
756771
setTurningCooldownTurns(this.turningCooldownTurns + GameConstants.HIT_TARGET_COOLDOWN);
@@ -776,7 +791,6 @@ public void travelFlying(boolean isSecondMove) {
776791
this.addHealth(-this.getHealth()); // rat dies :(
777792
// put cat to sleep
778793
this.gameWorld.getRobot(newLoc).sleepTimeRemaining = GameConstants.CAT_SLEEP_TIME;
779-
this.gameWorld.getMatchMaker().addCatFeedAction(this.getID());
780794
return;
781795
} else if (this.gameWorld.getRobot(newLoc) != null || !this.gameWorld.isPassable(newLoc)) {
782796
this.hitTarget(isSecondMove);
@@ -1083,8 +1097,10 @@ public void processBeginningOfTurn() {
10831097
if (this.remainingThrowDuration == 0) { // max throw time reached
10841098
this.hitGround();
10851099
} else {
1086-
this.travelFlying(false);
1087-
this.travelFlying(true); // This will call hitTarget or hitGround if we hit something
1100+
if (!this.gameWorld.getHasTraveledRobot(this.ID)){
1101+
this.travelFlying(false);
1102+
this.travelFlying(true); // This will call hitTarget or hitGround if we hit something
1103+
}
10881104
}
10891105
}
10901106

@@ -1113,13 +1129,11 @@ public void processEndOfTurn() {
11131129
}
11141130

11151131
// cat algo
1116-
1117-
if (this.type == UnitType.CAT) {
1118-
if (this.sleepTimeRemaining > 0) {
1119-
this.sleepTimeRemaining -= 1;
1120-
return;
1121-
}
1122-
1132+
if (this.type == UnitType.CAT && this.sleepTimeRemaining > 0){
1133+
this.gameWorld.getMatchMaker().addCatFeedAction(this.getID());
1134+
this.sleepTimeRemaining -= 1;
1135+
}
1136+
else if (this.type == UnitType.CAT) {
11231137
int[] pounceTraj = null;
11241138

11251139
switch (this.catState) {
@@ -1196,11 +1210,9 @@ public void processEndOfTurn() {
11961210
if (isStuck){
11971211
if (this.controller.canTurn()) {
11981212
try {
1199-
Direction newDirection = this.dir.rotateRight();
1200-
if (this.chirality == 0) this.controller.turn(newDirection);
1201-
else this.controller.turn(this.gameWorld.flipDirBySymmetry(newDirection));
1202-
} catch (GameActionException e) {
1203-
}
1213+
if (this.chirality == 0) this.controller.turn(this.dir.rotateRight());
1214+
else this.controller.turn(this.dir.rotateLeft());
1215+
} catch (GameActionException e) {}
12041216
}
12051217
}
12061218
}
@@ -1225,8 +1237,7 @@ public void processEndOfTurn() {
12251237
} else if (this.controller.canMove(this.dir)) {
12261238
try {
12271239
this.controller.move(this.dir);
1228-
} catch (GameActionException e) {
1229-
}
1240+
} catch (GameActionException e) {}
12301241
} else {
12311242
boolean isStuck = true;
12321243
for (MapLocation partLoc : this.getAllPartLocations()) {
@@ -1253,9 +1264,8 @@ else if (this.controller.canAttack(nextLoc)) {
12531264
if (isStuck){
12541265
if (this.controller.canTurn()) {
12551266
try {
1256-
Direction newDirection = this.dir.rotateRight();
1257-
if (this.chirality == 0) this.controller.turn(newDirection);
1258-
else this.controller.turn(this.gameWorld.flipDirBySymmetry(newDirection));
1267+
if (this.chirality == 0) this.controller.turn(this.dir.rotateRight());
1268+
else this.controller.turn(this.dir.rotateLeft());
12591269
} catch (GameActionException e) {
12601270
continue;
12611271
}
@@ -1353,13 +1363,10 @@ else if (this.controller.canAttack(nextLoc)) {
13531363
} catch (GameActionException e) {
13541364
continue;
13551365
}
1356-
1357-
}
1358-
else if (this.controller.canAttack(nextLoc)) {
1366+
} else if (this.controller.canAttack(nextLoc)) {
13591367
try {
1360-
Direction newDirection = this.dir.rotateRight();
1361-
if (this.chirality == 0) this.controller.turn(newDirection);
1362-
else this.controller.turn(this.gameWorld.flipDirBySymmetry(newDirection));
1368+
if (this.chirality == 0) this.controller.turn(this.dir.rotateRight());
1369+
else this.controller.turn(this.dir.rotateLeft());
13631370
} catch (GameActionException e) {
13641371
continue;
13651372
}
@@ -1368,11 +1375,9 @@ else if (this.controller.canAttack(nextLoc)) {
13681375

13691376
if (isStuck){
13701377
try {
1371-
Direction newDirection = this.dir.rotateRight();
1372-
if (this.chirality == 0) this.controller.turn(newDirection);
1373-
else this.controller.turn(this.gameWorld.flipDirBySymmetry(newDirection));
1374-
} catch (GameActionException e) {
1375-
}
1378+
if (this.chirality == 0) this.controller.turn(this.dir.rotateRight());
1379+
else this.controller.turn(this.dir.rotateLeft());
1380+
} catch (GameActionException e) {}
13761381
}
13771382
}
13781383
break;

0 commit comments

Comments
 (0)