Skip to content

Commit 5afa4b7

Browse files
committed
add rat king cutoff round
1 parent 51f55a7 commit 5afa4b7

File tree

5 files changed

+66
-13
lines changed

5 files changed

+66
-13
lines changed

engine/src/crossplay_python/battlecode26/classes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ class GameConstants:
279279
EXCEPTION_BYTECODE_PENALTY = 500
280280
INITIAL_TEAM_CHEESE = 2500
281281
MAX_NUMBER_OF_RAT_KINGS = 5
282+
MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF = 2
283+
RAT_KING_CUTOFF_ROUND = 1200
282284
MAX_TEAM_EXECUTION_TIME = 1200000000000
283285
MOVE_STRAFE_COOLDOWN = 18
284286
CHEESE_COOLDOWN_PENALTY = 0.01
@@ -295,6 +297,8 @@ class GameConstants:
295297
BUILD_ROBOT_COST_INCREASE = 10
296298
NUM_ROBOTS_FOR_COST_INCREASE = 4
297299
BUILD_DISTANCE_SQUARED = 2
300+
RAT_KING_BUILD_DISTANCE_SQUARED = 8
301+
ATTACK_DISTANCE_SQUARED = 2
298302
RAT_KING_ATTACK_DISTANCE_SQUARED = 8
299303
MESSAGE_ROUND_DURATION = 5
300304
MAX_MESSAGES_SENT_ROBOT = 1

engine/src/crossplay_python/python_docs.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,8 @@ class GameConstants:
533533
EXCEPTION_BYTECODE_PENALTY = 500
534534
INITIAL_TEAM_CHEESE = 2500
535535
MAX_NUMBER_OF_RAT_KINGS = 5
536+
MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF = 2
537+
RAT_KING_CUTOFF_ROUND = 1200
536538
MAX_TEAM_EXECUTION_TIME = 1200000000000
537539
MOVE_STRAFE_COOLDOWN = 18
538540
CHEESE_COOLDOWN_PENALTY = 0.01
@@ -549,6 +551,8 @@ class GameConstants:
549551
BUILD_ROBOT_COST_INCREASE = 10
550552
NUM_ROBOTS_FOR_COST_INCREASE = 4
551553
BUILD_DISTANCE_SQUARED = 2
554+
RAT_KING_BUILD_DISTANCE_SQUARED = 8
555+
ATTACK_DISTANCE_SQUARED = 2
552556
RAT_KING_ATTACK_DISTANCE_SQUARED = 8
553557
MESSAGE_ROUND_DURATION = 5
554558
MAX_MESSAGES_SENT_ROBOT = 1

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,20 @@ public class GameConstants {
6464
/** The maximum number of rat kings that a team can have. */
6565
public static final int MAX_NUMBER_OF_RAT_KINGS = 5;
6666

67+
/**
68+
* The maximum number of rat kings that a team can have after the cutoff round.
69+
* Rat kings created before the cutoff round are never destroyed,
70+
* even if the team exceeds the new maximum.
71+
*/
72+
public static final int MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF = 2;
73+
74+
/**
75+
* The round after which the maximum number of rat kings is reduced.
76+
* Rat kings created before this round are never destroyed,
77+
* even if the team exceeds the new maximum.
78+
*/
79+
public static final int RAT_KING_CUTOFF_ROUND = 1200;
80+
6781
/**
6882
* The maximum execution time that can be spent on a team in one match. If the
6983
* total time spent executing a team's bots
@@ -109,7 +123,11 @@ public class GameConstants {
109123
/** The maximum distance for transferring cheese to an allied rat king */
110124
public static final int CHEESE_TRANSFER_RADIUS_SQUARED = 9;
111125

112-
/** The maximum distance for picking up cheese on the map */
126+
/**
127+
* The maximum distance for picking up cheese on the map.
128+
* This also applies to rat kings, so rat kings can only pick up cheese
129+
* which is under one of their tiles.
130+
*/
113131
public static final int CHEESE_PICK_UP_RADIUS_SQUARED = 2;
114132

115133
/** The maximum distance from a rat king for building robots */
@@ -133,6 +151,16 @@ public class GameConstants {
133151
/** The maximum distance from a robot for building traps or dirt */
134152
public static final int BUILD_DISTANCE_SQUARED = 2;
135153

154+
/**
155+
* The maximum distance squared a rat king can build traps or dirt,
156+
* measured from the king's center. All rats (including rat kings)
157+
* can only build on adjacent squares, and the rat king is 3x3, so this is 8.
158+
*/
159+
public static final int RAT_KING_BUILD_DISTANCE_SQUARED = 8;
160+
161+
/** The maximum distance squared a robot can attack */
162+
public static final int ATTACK_DISTANCE_SQUARED = 2;
163+
136164
/**
137165
* The maximum distance squared a rat king can attack, measured from the king's center.
138166
* All rats (including rat kings) can only attack adjacent squares,

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,9 @@ public void bite(MapLocation loc, int cheeseConsumed) {
574574
// Must be an immediate neighbor
575575
int distSq = this.location.distanceSquaredTo(loc);
576576

577-
if (!(distSq > 0 && (distSq <= 2 || (this.type == UnitType.RAT_KING
578-
&& distSq <= GameConstants.RAT_KING_ATTACK_DISTANCE_SQUARED)))) {
577+
if (distSq == 0 || distSq > (this.type == UnitType.RAT_KING
578+
? GameConstants.RAT_KING_ATTACK_DISTANCE_SQUARED
579+
: GameConstants.ATTACK_DISTANCE_SQUARED)) {
579580
return;
580581
}
581582

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

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,13 @@ private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws
230230
// }
231231

232232
private void assertCanPlaceDirt(MapLocation loc) throws GameActionException {
233+
UnitType myType = this.robot.getType();
234+
233235
assertIsActionReady();
234-
assertIsRobotType(this.robot.getType());
235-
// Use unit action radius as the allowed range for the action
236-
assertCanActLocation(loc, GameConstants.BUILD_DISTANCE_SQUARED);
237-
assertIsActionReady();
236+
assertIsRobotType(myType);
237+
assertCanActLocation(loc, myType == UnitType.RAT_KING
238+
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
239+
: GameConstants.BUILD_DISTANCE_SQUARED);
238240

239241
// state checks :
240242
if (this.gameWorld.getTeamInfo().getDirt(this.robot.getTeam()) <= 0)
@@ -308,10 +310,13 @@ private void assertCanRemoveRatTrap(MapLocation loc) throws GameActionException
308310
}
309311

310312
private void assertCanPlaceTrap(MapLocation loc, TrapType trapType) throws GameActionException {
311-
assertIsRobotType(this.robot.getType());
312-
assertIsActionReady();
313-
assertCanActLocation(loc, GameConstants.BUILD_DISTANCE_SQUARED);
313+
UnitType myType = this.robot.getType();
314+
314315
assertIsActionReady();
316+
assertIsRobotType(myType);
317+
assertCanActLocation(loc, myType == UnitType.RAT_KING
318+
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
319+
: GameConstants.BUILD_DISTANCE_SQUARED);
315320

316321
if (trapType == TrapType.CAT_TRAP && !this.gameWorld.isCooperation)
317322
throw new GameActionException(CANT_DO_THAT, "Can't place new cat traps in backstabbing mode!");
@@ -965,8 +970,11 @@ private void assertCanAttackRat(MapLocation loc, int cheeseConsumed) throws Game
965970
assertCanActLocation(loc, myType.getVisionRadiusSquared());
966971

967972
MapLocation myLoc = this.getLocation();
973+
int distSq = myLoc.distanceSquaredTo(loc);
968974

969-
if (!myLoc.isAdjacentTo(loc) && !(myType.isRatKingType() && myLoc.distanceSquaredTo(loc) <= GameConstants.RAT_KING_ATTACK_DISTANCE_SQUARED)) {
975+
if (distSq == 0 || distSq > (myType == UnitType.RAT_KING
976+
? GameConstants.RAT_KING_ATTACK_DISTANCE_SQUARED
977+
: GameConstants.ATTACK_DISTANCE_SQUARED)) {
970978
throw new GameActionException(CANT_DO_THAT, "Rats can only attack adjacent squares!");
971979
}
972980

@@ -1081,8 +1089,16 @@ public void assertCanBecomeRatKing() throws GameActionException {
10811089
throw new GameActionException(CANT_DO_THAT, "Not enough cheese to upgrade to a rat king");
10821090
}
10831091

1084-
if (teamInfo.getNumRatKings(this.robot.getTeam()) >= GameConstants.MAX_NUMBER_OF_RAT_KINGS){
1085-
throw new GameActionException(CANT_DO_THAT, "Cannot have more than " +GameConstants.MAX_NUMBER_OF_RAT_KINGS + "rat kings per team!" );
1092+
int numRatKings = teamInfo.getNumRatKings(this.robot.getTeam());
1093+
1094+
if (numRatKings >= GameConstants.MAX_NUMBER_OF_RAT_KINGS) {
1095+
throw new GameActionException(CANT_DO_THAT, "Cannot have more than " + GameConstants.MAX_NUMBER_OF_RAT_KINGS + " rat kings per team!");
1096+
}
1097+
1098+
if (numRatKings >= GameConstants.MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF && this.gameWorld.getCurrentRound() > GameConstants.RAT_KING_CUTOFF_ROUND) {
1099+
throw new GameActionException(CANT_DO_THAT,
1100+
"Cannot make a new rat king when your team has at least " + GameConstants.MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF
1101+
+ " rat kings after round " + GameConstants.RAT_KING_CUTOFF_ROUND + "!");
10861102
}
10871103

10881104
int numAllyRats = 0;

0 commit comments

Comments
 (0)