Skip to content

Commit 1d95856

Browse files
committed
Merge branch 'master' into engine-release
2 parents 895616f + 2ce14e3 commit 1d95856

File tree

4 files changed

+53
-38
lines changed

4 files changed

+53
-38
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,12 @@ public class GameConstants {
130130
*/
131131
public static final int CHEESE_PICK_UP_RADIUS_SQUARED = 2;
132132

133-
/** The maximum distance from a rat king for building robots */
134-
public static final int BUILD_ROBOT_RADIUS_SQUARED = 4;
133+
/**
134+
* The maximum distance from a rat king for building robots
135+
* from the king's center. Effectively only adjacent squares,
136+
* since the rat king is 3x3.
137+
*/
138+
public static final int BUILD_ROBOT_RADIUS_SQUARED = 8;
135139

136140
/** The base cheese cost for spawning a rat */
137141
public static final int BUILD_ROBOT_BASE_COST = 10;

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

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GameWorld {
3333

3434
private int[] cheeseAmounts;
3535
private InternalRobot[][] robots;
36-
private Trap[] trapLocations;
36+
private Trap[][] trapLocations;
3737
private ArrayList<Trap>[] trapTriggers;
3838
private HashMap<TrapType, int[]> trapCounts; // maps trap type to counts for each team
3939
private final LiveMap gameMap;
@@ -138,7 +138,7 @@ public GameWorld(LiveMap gm, RobotControlProvider cp, GameMaker.MatchMaker match
138138
this.walls = gm.getWallArray();
139139
this.dirt = gm.getDirtArray();
140140
this.cheeseAmounts = gm.getCheeseArray();
141-
this.trapLocations = new Trap[numSquares]; // We guarantee that no maps will contain traps at t = 0
141+
this.trapLocations = new Trap[2][numSquares]; // We guarantee that no maps will contain traps at t = 0
142142
this.robots = new InternalRobot[width][height]; // if represented in cartesian, should be height-width, but this
143143
// should allow us to index x-y
144144
this.hasRunCheeseMinesThisRound = false;
@@ -534,21 +534,21 @@ public boolean hasCheeseMine(MapLocation loc) {
534534
// ****** TRAP METHODS **************
535535
// ***********************************
536536

537-
public Trap getTrap(MapLocation loc) {
538-
return this.trapLocations[locationToIndex(loc)];
537+
public Trap getTrap(MapLocation loc, Team team) {
538+
return this.trapLocations[team.ordinal()][locationToIndex(loc)];
539539
}
540540

541-
public boolean hasTrap(MapLocation loc) {
542-
return (this.trapLocations[locationToIndex(loc)] != null);
541+
public boolean hasTrap(MapLocation loc, Team team) {
542+
return (this.trapLocations[team.ordinal()][locationToIndex(loc)] != null);
543543
}
544544

545-
public boolean hasRatTrap(MapLocation loc) {
546-
Trap trap = this.trapLocations[locationToIndex(loc)];
545+
public boolean hasRatTrap(MapLocation loc, Team team) {
546+
Trap trap = this.trapLocations[team.ordinal()][locationToIndex(loc)];
547547
return (trap != null && trap.getType() == TrapType.RAT_TRAP);
548548
}
549549

550-
public boolean hasCatTrap(MapLocation loc) {
551-
Trap trap = this.trapLocations[locationToIndex(loc)];
550+
public boolean hasCatTrap(MapLocation loc, Team team) {
551+
Trap trap = this.trapLocations[team.ordinal()][locationToIndex(loc)];
552552
return (trap != null && trap.getType() == TrapType.CAT_TRAP);
553553
}
554554

@@ -557,12 +557,11 @@ public ArrayList<Trap> getTrapTriggers(MapLocation loc) {
557557
}
558558

559559
public void placeTrap(MapLocation loc, Trap trap) {
560-
561560
TrapType type = trap.getType();
562561
Team team = trap.getTeam();
563562

564563
int idx = locationToIndex(loc);
565-
this.trapLocations[idx] = trap;
564+
this.trapLocations[team.ordinal()][idx] = trap;
566565

567566
for (MapLocation adjLoc : getAllLocationsWithinRadiusSquared(loc, type.triggerRadiusSquared, 0)) {// set chirality to 0, only rats will be placing traps
568567
this.trapTriggers[locationToIndex(adjLoc)].add(trap);
@@ -573,17 +572,18 @@ public void placeTrap(MapLocation loc, Trap trap) {
573572
this.trapCounts.put(type, trapTypeCounts);
574573
}
575574

576-
public void removeTrap(MapLocation loc) {
577-
Trap trap = this.trapLocations[locationToIndex(loc)];
575+
public void removeTrap(MapLocation loc, Team team) {
576+
Trap trap = this.trapLocations[team.ordinal()][locationToIndex(loc)];
577+
578578
if (trap == null) {
579579
return;
580580
}
581+
581582
TrapType type = trap.getType();
582-
Team team = trap.getTeam();
583583
int[] trapTypeCounts = this.trapCounts.get(type);
584584
trapTypeCounts[team.ordinal()] -= 1;
585585
this.trapCounts.put(type, trapTypeCounts);
586-
this.trapLocations[locationToIndex(loc)] = null;
586+
this.trapLocations[team.ordinal()][locationToIndex(loc)] = null;
587587

588588
for (MapLocation adjLoc : getAllLocationsWithinRadiusSquared(loc, type.triggerRadiusSquared, 0)) { // set chirality to 0, only rats will be removing traps
589589
this.trapTriggers[locationToIndex(adjLoc)].remove(trap);
@@ -612,7 +612,7 @@ public void triggerTrap(Trap trap, InternalRobot robot) {
612612

613613
matchMaker.addTrapTriggerAction(trap.getId(), loc, triggeringTeam, type);
614614

615-
removeTrap(loc);
615+
removeTrap(loc, trap.getTeam());
616616
robot.addHealth(-type.damage);
617617
// matchMaker.addAction(robot.getID(),
618618
// FlatHelpers.getTrapActionFromTrapType(type),

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

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ private InternalRobot getRobotByID(int id) {
7272
// }
7373

7474
private MapInfo getMapInfo(MapLocation loc) throws GameActionException {
75+
Team team = this.getTeam();
7576
GameWorld gw = this.gameWorld;
76-
Trap trap = gw.getTrap(loc);
77-
TrapType trapType = (trap != null && trap.getTeam() == this.getTeam()) ? trap.getType() : TrapType.NONE;
77+
Trap trap = gw.getTrap(loc, team);
78+
TrapType trapType = (trap != null) ? trap.getType() : TrapType.NONE;
7879
MapInfo currentLocInfo = new MapInfo(loc, gw.isPassable(loc), gw.getWall(loc), gw.getDirt(loc),
7980
gw.getCheeseAmount(loc), trapType,
8081
gw.hasCheeseMine(loc));
@@ -212,9 +213,11 @@ private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws
212213
? (getLocation().bottomLeftDistanceSquaredTo(loc))
213214
: (getLocation().distanceSquaredTo(loc));
214215

215-
float addDistance = (float) Math.ceil((this.getType().size / (2.0) + Math.sqrt((double) maxRadiusSquared))
216-
* (this.getType().size / 2.0 + Math.sqrt((double) maxRadiusSquared)));
217-
if (distance > (addDistance))
216+
// float addDistance = (float) Math.ceil((this.getType().size / (2.0) + Math.sqrt((double) maxRadiusSquared))
217+
// * (this.getType().size / 2.0 + Math.sqrt((double) maxRadiusSquared)));
218+
float addDistance = maxRadiusSquared;
219+
220+
if (distance > addDistance)
218221
throw new GameActionException(OUT_OF_RANGE,
219222
"Target location not within action range");
220223
}
@@ -304,16 +307,16 @@ public boolean canRemoveDirt(MapLocation loc) {
304307

305308
private void assertCanRemoveRatTrap(MapLocation loc) throws GameActionException {
306309
UnitType myType = this.robot.getType();
310+
Team myTeam = this.getTeam();
307311

308312
assertIsRobotType(myType);
309313
assertCanActLocation(loc, myType == UnitType.RAT_KING
310314
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
311315
: GameConstants.BUILD_DISTANCE_SQUARED);
312316

313-
if (!this.gameWorld.hasRatTrap(loc))
317+
if (!this.gameWorld.hasRatTrap(loc, myTeam)) {
314318
throw new GameActionException(CANT_DO_THAT, "No rat trap to remove at that location!");
315-
if (this.gameWorld.getTrap(loc).getTeam() != this.getTeam())
316-
throw new GameActionException(CANT_DO_THAT, "Can't remove an enemy team's rat trap!");
319+
}
317320
}
318321

319322
private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameActionException {
@@ -331,7 +334,7 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
331334
throw new GameActionException(CANT_DO_THAT, "Can't place trap on a wall or dirt!");
332335
if (this.gameWorld.getRobot(loc) != null)
333336
throw new GameActionException(CANT_DO_THAT, "Can't place trap on an occupied tile!");
334-
if (this.gameWorld.hasTrap(loc))
337+
if (this.gameWorld.hasTrap(loc, this.robot.getTeam()))
335338
throw new GameActionException(CANT_DO_THAT, "Tile already has a trap!");
336339
if (this.gameWorld.getTrapCount(trapType, this.robot.getTeam()) >= trapType.maxCount)
337340
throw new GameActionException(CANT_DO_THAT,
@@ -344,11 +347,16 @@ private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameA
344347
}
345348

346349
private void assertCanRemoveCatTrap(MapLocation loc) throws GameActionException {
347-
assertIsRobotType(this.robot.getType());
348-
assertCanActLocation(loc, GameConstants.BUILD_DISTANCE_SQUARED);
350+
UnitType myType = this.robot.getType();
349351

350-
if (!this.gameWorld.hasCatTrap(loc))
352+
assertIsRobotType(myType);
353+
assertCanActLocation(loc, myType == UnitType.RAT_KING
354+
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
355+
: GameConstants.BUILD_DISTANCE_SQUARED);
356+
357+
if (!this.gameWorld.hasCatTrap(loc, this.getTeam())) {
351358
throw new GameActionException(CANT_DO_THAT, "No cat trap to remove at that location!");
359+
}
352360
}
353361

354362
@Override
@@ -379,9 +387,10 @@ public boolean canRemoveRatTrap(MapLocation loc) {
379387

380388
@Override
381389
public void removeRatTrap(MapLocation loc) throws GameActionException {
390+
Team team = this.getTeam();
382391
assertCanRemoveRatTrap(loc);
383-
Trap trap = this.gameWorld.getTrap(loc);
384-
this.gameWorld.removeTrap(loc);
392+
Trap trap = this.gameWorld.getTrap(loc, team);
393+
this.gameWorld.removeTrap(loc, team);
385394
this.gameWorld.getMatchMaker().addRemoveTrapAction(trap.getLocation(), trap.getTeam());
386395
}
387396

@@ -413,9 +422,10 @@ public boolean canRemoveCatTrap(MapLocation loc) {
413422

414423
@Override
415424
public void removeCatTrap(MapLocation loc) throws GameActionException {
425+
Team team = this.getTeam();
416426
assertCanRemoveCatTrap(loc);
417-
Trap trap = this.gameWorld.getTrap(loc);
418-
this.gameWorld.removeTrap(loc);
427+
Trap trap = this.gameWorld.getTrap(loc, team);
428+
this.gameWorld.removeTrap(loc, team);
419429
this.gameWorld.getMatchMaker().addRemoveTrapAction(trap.getLocation(), trap.getTeam());
420430
}
421431

@@ -959,11 +969,12 @@ public void buildTrap(TrapType type, MapLocation loc) throws GameActionException
959969
this.robot.addActionCooldownTurns(type.actionCooldown);
960970
this.robot.addCheese(-type.buildCost);
961971

972+
Team team = this.getTeam();
962973
int trapId = this.gameWorld.idGenerator.nextID();
963-
Trap newTrap = new Trap(loc, type, this.getTeam(), trapId);
974+
Trap newTrap = new Trap(loc, type, team, trapId);
964975

965976
this.gameWorld.placeTrap(loc, newTrap);
966-
this.gameWorld.getMatchMaker().addPlaceTrapAction(trapId, loc, getTeam(), type);
977+
this.gameWorld.getMatchMaker().addPlaceTrapAction(trapId, loc, team, type);
967978
}
968979

969980
// *****************************
@@ -1284,7 +1295,7 @@ private void assertCanTransferCheese(MapLocation loc, int amount) throws GameAct
12841295
throw new GameActionException(CANT_DO_THAT, "Cannot transfer resources to the enemy team!");
12851296
}
12861297
if (!this.robot.getType().isBabyRatType()) {
1287-
throw new GameActionException(CANT_DO_THAT, "Only rats can transfer cheese!");
1298+
throw new GameActionException(CANT_DO_THAT, "Only baby rats can transfer cheese!");
12881299
}
12891300
if (!robot.getType().isRatKingType()) {
12901301
throw new GameActionException(CANT_DO_THAT, "Only rat kings can receive cheese!");

specs/specs.pdf

661 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)