Skip to content

Commit 895616f

Browse files
committed
Merge branch 'master' into engine-release
2 parents 5a8db53 + cd603b7 commit 895616f

File tree

9 files changed

+136
-66
lines changed

9 files changed

+136
-66
lines changed

engine/src/crossplay_python/battlecode26/classes.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,18 +189,16 @@ def __repr__(self) -> str:
189189

190190

191191
class TrapType(_Enum):
192-
RAT_TRAP = (30, 50, 20, 25, 15, 0, 25, 2)
193-
CAT_TRAP = (10, 100, 20, 5, 10, 0, 10, 2)
194-
NONE = (0, 0, 0, 0, 0, 0, 0, 0)
192+
RAT_TRAP = (30, 50, 20, 15, 25, 2)
193+
CAT_TRAP = (10, 100, 20, 10, 10, 2)
194+
NONE = (0, 0, 0, 0, 0, 0)
195195

196-
def __init__(self, build_cost: int, damage: int, stun_time: int, trap_limit: int,
197-
action_cooldown: int, spawn_cheese_amount: int, max_count: int, trigger_radius_squared: int):
196+
def __init__(self, build_cost: int, damage: int, stun_time: int,
197+
action_cooldown: int, max_count: int, trigger_radius_squared: int):
198198
self.build_cost = build_cost
199199
self.damage = damage
200200
self.stun_time = stun_time
201-
self.trap_limit = trap_limit
202201
self.action_cooldown = action_cooldown
203-
self.spawn_cheese_amount = spawn_cheese_amount
204202
self.max_count = max_count
205203
self.trigger_radius_squared = trigger_radius_squared
206204

@@ -281,6 +279,8 @@ class GameConstants:
281279
EXCEPTION_BYTECODE_PENALTY = 500
282280
INITIAL_TEAM_CHEESE = 2500
283281
MAX_NUMBER_OF_RAT_KINGS = 5
282+
MAX_NUMBER_OF_RAT_KINGS_AFTER_CUTOFF = 2
283+
RAT_KING_CUTOFF_ROUND = 1200
284284
MAX_TEAM_EXECUTION_TIME = 1200000000000
285285
MOVE_STRAFE_COOLDOWN = 18
286286
CHEESE_COOLDOWN_PENALTY = 0.01
@@ -297,6 +297,8 @@ class GameConstants:
297297
BUILD_ROBOT_COST_INCREASE = 10
298298
NUM_ROBOTS_FOR_COST_INCREASE = 4
299299
BUILD_DISTANCE_SQUARED = 2
300+
RAT_KING_BUILD_DISTANCE_SQUARED = 8
301+
ATTACK_DISTANCE_SQUARED = 2
300302
RAT_KING_ATTACK_DISTANCE_SQUARED = 8
301303
MESSAGE_ROUND_DURATION = 5
302304
MAX_MESSAGES_SENT_ROBOT = 1
@@ -309,8 +311,8 @@ class GameConstants:
309311
CAT_DIG_ADDITIONAL_COOLDOWN = 5
310312
HEALTH_GRAB_THRESHOLD = 0
311313
RAT_KING_UPGRADE_CHEESE_COST = 50
312-
DIG_DIRT_CHEESE_COST = 10
313-
PLACE_DIRT_CHEESE_COST = 10
314+
DIG_DIRT_CHEESE_COST = 5
315+
PLACE_DIRT_CHEESE_COST = 3
314316
SHARED_ARRAY_SIZE = 64
315317
COMM_ARRAY_MAX_VALUE = 1023
316318
COOLDOWN_LIMIT = 10
@@ -322,6 +324,7 @@ class GameConstants:
322324
CARRY_COOLDOWN_MULTIPLIER = 1.5
323325
MAX_CARRY_TOWER_HEIGHT = 2
324326
MAX_CARRY_DURATION = 10
327+
SAME_ROBOT_CARRY_COOLDOWN_TURNS = 2
325328
THROW_DURATION = 4
326329
HIT_GROUND_COOLDOWN = 10
327330
HIT_TARGET_COOLDOWN = 30

engine/src/crossplay_python/python_docs.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Battlecode 2026 Python Documentation
2-
v1.1.4
2+
v1.1.5
33

44
## Getting Started
55

@@ -25,6 +25,8 @@ The Battlecode match runner restricts which libraries you are allowed to use, be
2525

2626
Below is a list of functions you can use to control your team's rats. Most are the same as Java but with camelCase changed to snake\_case, but one key change is that some of the `MapLocation` and `UnitType` methods were made into global functions, while others were kept as methods for those classes. See the Javadoc for detailed explanations of each of these functions. If there is a method supported by the Java engine which is missing here, please let us know in the Battlecode Discord server.
2727

28+
Important: Use `log` instead of `print` for printing debug messages for your bot!
29+
2830
```python
2931
def log(*messages) -> None:
3032
pass
@@ -459,15 +461,13 @@ class TrapType(Enum):
459461
- build_cost: int
460462
- damage: int
461463
- stun_time: int
462-
- trap_limit: int
463464
- action_cooldown: int
464-
- spawn_cheese_amount: int
465465
- max_count: int
466466
- trigger_radius_squared: int
467467
"""
468-
RAT_TRAP = (30, 50, 20, 25, 15, 0, 25, 2)
469-
CAT_TRAP = (10, 100, 20, 5, 10, 0, 10, 2)
470-
NONE = (0, 0, 0, 0, 0, 0, 0, 0)
468+
RAT_TRAP = (30, 50, 20, 15, 25, 2)
469+
CAT_TRAP = (10, 100, 20, 10, 10, 2)
470+
NONE = (0, 0, 0, 0, 0, 0, 0)
471471

472472
def ordinal(self) -> int:
473473
"""
@@ -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
@@ -561,8 +565,8 @@ class GameConstants:
561565
CAT_DIG_ADDITIONAL_COOLDOWN = 5
562566
HEALTH_GRAB_THRESHOLD = 0
563567
RAT_KING_UPGRADE_CHEESE_COST = 50
564-
DIG_DIRT_CHEESE_COST = 10
565-
PLACE_DIRT_CHEESE_COST = 10
568+
DIG_DIRT_CHEESE_COST = 5
569+
PLACE_DIRT_CHEESE_COST = 3
566570
SHARED_ARRAY_SIZE = 64
567571
COMM_ARRAY_MAX_VALUE = 1023
568572
COOLDOWN_LIMIT = 10
@@ -574,6 +578,7 @@ class GameConstants:
574578
CARRY_COOLDOWN_MULTIPLIER = 1.5
575579
MAX_CARRY_TOWER_HEIGHT = 2
576580
MAX_CARRY_DURATION = 10
581+
SAME_ROBOT_CARRY_COOLDOWN_TURNS = 2
577582
THROW_DURATION = 4
578583
HIT_GROUND_COOLDOWN = 10
579584
HIT_TARGET_COOLDOWN = 30

engine/src/crossplay_python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,5 @@
2626
],
2727
python_requires='>=3.12, <3.13',
2828
zip_safe=False,
29-
version='1.1.4',
29+
version='1.1.5',
3030
)

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

Lines changed: 38 additions & 3 deletions
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,
@@ -181,10 +209,10 @@ public class GameConstants {
181209
public static final int RAT_KING_UPGRADE_CHEESE_COST = 50;
182210

183211
/** The cheese cost to dig up a tile of dirt */
184-
public static final int DIG_DIRT_CHEESE_COST = 10;
212+
public static final int DIG_DIRT_CHEESE_COST = 5;
185213

186214
/** The cheese cost to place a tile of dirt */
187-
public static final int PLACE_DIRT_CHEESE_COST = 10;
215+
public static final int PLACE_DIRT_CHEESE_COST = 3;
188216

189217

190218
// *********************************
@@ -241,6 +269,13 @@ public class GameConstants {
241269
/** The maximum number of turns of robots a rat can carry another rat */
242270
public static final int MAX_CARRY_DURATION = 10;
243271

272+
/**
273+
* The minimum number of turns after a robot hits the ground or is dropped before it
274+
* can be grabbed again by its most recent grabber. Turns are counted so that the
275+
* turn on which it is thrown or dropped is turn 0.
276+
*/
277+
public static final int SAME_ROBOT_CARRY_COOLDOWN_TURNS = 2;
278+
244279
/**
245280
* The total number turns a rat can travel for while thrown (rats are stunned while thrown)
246281
*/

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ public enum TrapType {
99
/**
1010
* Traps enemy rats
1111
*/
12-
RAT_TRAP(30, 50, 20, 25, 15, 0, 25, 2),
12+
RAT_TRAP(20, 50, 30, 15, 25, 2),
1313

1414
/**
1515
* Traps the cat
1616
*/
17-
CAT_TRAP(10, 100, 20, 5, 10, 0, 10, 2),
17+
CAT_TRAP(10, 100, 20, 10, 10, 2),
1818

1919
/**
2020
* No trap
2121
*/
22-
NONE(0, 0, 0, 0, 0, 0, 0, 0);
22+
NONE(0, 0, 0, 0, 0, 0);
2323

2424
/**
2525
* Crumbs cost of each trap
@@ -36,21 +36,11 @@ public enum TrapType {
3636
*/
3737
public final int stunTime;
3838

39-
/**
40-
* How many traps of this type can be on the map at the same time
41-
*/
42-
public final int trapLimit;
43-
4439
/*
4540
* action cooldown for trap placement
4641
*/
4742
public final int actionCooldown;
4843

49-
/**
50-
* Amount of cheese that spawns with the rat trap, if there isn't already at least this much cheese on the trap location
51-
*/
52-
public final int spawnCheeseAmount;
53-
5444
/**
5545
* Maximum number of this trap type that a team can have active at once
5646
*/
@@ -62,13 +52,11 @@ public enum TrapType {
6252
public final int triggerRadiusSquared;
6353

6454

65-
TrapType(int buildCost, int damage, int stunTime, int trapLimit, int actionCooldown, int spawnCheeseAmount, int maxCount, int triggerRadiusSquared) {
55+
TrapType(int buildCost, int damage, int stunTime, int actionCooldown, int maxCount, int triggerRadiusSquared) {
6656
this.buildCost = buildCost;
6757
this.damage = damage;
6858
this.stunTime = stunTime;
69-
this.trapLimit = trapLimit;
7059
this.actionCooldown = actionCooldown;
71-
this.spawnCheeseAmount = spawnCheeseAmount;
7260
this.maxCount = maxCount;
7361
this.triggerRadiusSquared = triggerRadiusSquared;
7462
}

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ public class InternalRobot implements Comparable<InternalRobot> {
4343
private int movementCooldownTurns;
4444
private int turningCooldownTurns;
4545

46+
private int turnsSinceThrownOrDropped;
47+
private int lastGrabberId;
4648
private InternalRobot robotBeingCarried; // robot being carried by this robot, if any
4749
private InternalRobot grabbedByRobot; // robot that is carrying this robot, if any
4850
private Direction thrownDir;
@@ -105,6 +107,8 @@ public InternalRobot(GameWorld gw, int id, Team team, UnitType type, MapLocation
105107
this.movementCooldownTurns = GameConstants.COOLDOWN_LIMIT;
106108
this.turningCooldownTurns = GameConstants.COOLDOWN_LIMIT;
107109

110+
this.turnsSinceThrownOrDropped = GameConstants.GAME_MAX_NUMBER_OF_ROUNDS; // not recently thrown or dropped
111+
this.lastGrabberId = -1;
108112
this.robotBeingCarried = null;
109113
this.grabbedByRobot = null;
110114
this.thrownDir = null;
@@ -304,6 +308,14 @@ public boolean isBeingThrown() {
304308
return thrownDir != null;
305309
}
306310

311+
public int getTurnsSinceThrownOrDropped() {
312+
return turnsSinceThrownOrDropped;
313+
}
314+
315+
public int getLastGrabberId() {
316+
return lastGrabberId;
317+
}
318+
307319
public RobotInfo getRobotInfo() {
308320
// We use the ID of the center of a big robot for sensing related methods
309321
// so that IDs are consistent regardless of which part of the robot is sensed
@@ -562,8 +574,9 @@ public void bite(MapLocation loc, int cheeseConsumed) {
562574
// Must be an immediate neighbor
563575
int distSq = this.location.distanceSquaredTo(loc);
564576

565-
if (!(distSq > 0 && (distSq <= 2 || (this.type == UnitType.RAT_KING
566-
&& 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)) {
567580
return;
568581
}
569582

@@ -662,7 +675,9 @@ private void swapGrabber() {
662675
}
663676

664677
private void getGrabbed(InternalRobot grabber) {
678+
this.turnsSinceThrownOrDropped = 0;
665679
this.grabbedByRobot = grabber;
680+
this.lastGrabberId = grabber.getID();
666681
this.gameWorld.removeRobot(getLocation());
667682

668683
if (this.isCarryingRobot()) { // If we were carrying a robot, drop it
@@ -689,7 +704,7 @@ public void throwRobot() {
689704
}
690705

691706
private void getThrown(Direction dir) {
692-
707+
this.turnsSinceThrownOrDropped = 0;
693708
this.grabbedByRobot = null;
694709
this.remainingCarriedDuration = 0;
695710
this.thrownDir = dir;
@@ -710,6 +725,7 @@ public void getDropped(MapLocation loc) {
710725
throw new RuntimeException("Cannot drop into impassable terrain");
711726
}
712727

728+
this.turnsSinceThrownOrDropped = 0;
713729
this.grabbedByRobot = null;
714730
this.remainingCarriedDuration = 0;
715731
this.setInternalLocationOnly(loc);
@@ -725,6 +741,7 @@ public void getDropped(MapLocation loc) {
725741
}
726742

727743
public void hitGround() {
744+
this.turnsSinceThrownOrDropped = 0;
728745
this.thrownDir = null;
729746
this.remainingThrowDuration = 0;
730747

@@ -734,7 +751,7 @@ public void hitGround() {
734751
this.gameWorld.getMatchMaker().addDamageAction(this.ID, damage);
735752
this.gameWorld.getMatchMaker().addRatNapAction(this.getID());
736753

737-
754+
738755
if (this.health > 0) {
739756
this.gameWorld.addRobot(this.location, this);
740757
this.controller.processTrapsAtLocation(this.location);
@@ -1111,6 +1128,7 @@ public void processBeginningOfTurn() {
11111128
// if rat is being carried or thrown, skip cooldown resets; same for a sleeping
11121129
// cat
11131130
boolean isSleepingCat = this.getType().isCatType() && this.sleepTimeRemaining > 0;
1131+
11141132
if (!this.isGrabbedByRobot() && !this.isBeingThrown() && !isSleepingCat) {
11151133
this.actionCooldownTurns = Math.max(0, this.actionCooldownTurns - GameConstants.COOLDOWNS_PER_TURN);
11161134
this.turningCooldownTurns = Math.max(0, this.turningCooldownTurns - GameConstants.COOLDOWNS_PER_TURN);
@@ -1122,6 +1140,10 @@ public void processBeginningOfTurn() {
11221140
}
11231141

11241142
public void processEndOfTurn() {
1143+
if (!this.isGrabbedByRobot() && !this.isBeingThrown()) {
1144+
this.turnsSinceThrownOrDropped += 1;
1145+
}
1146+
11251147
// eat cheese if rat king
11261148
if (this.type.isRatKingType() && this.gameWorld.getTeamInfo().getNumRatKings(this.getTeam()) > 0) {
11271149
// rat king starves

0 commit comments

Comments
 (0)