Skip to content

Commit 06a138a

Browse files
committed
Merge branch 'master' into engine-release
2 parents 51891e5 + c3045fd commit 06a138a

13 files changed

Lines changed: 147 additions & 58 deletions

File tree

engine/src/crossplay_python/battlecode26/crossplay.py

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,41 @@ class CrossPlayMethod(Enum):
9191
RC_REMOVE_CAT_TRAP = 67
9292
RC_CAN_PICK_UP_CHEESE = 68
9393
RC_PICK_UP_CHEESE = 69
94-
RC_CAN_ATTACK = 70
95-
RC_CAN_ATTACK__LOC_INT = 71
96-
RC_ATTACK = 72
97-
RC_ATTACK__LOC_INT = 73
98-
RC_SQUEAK = 74
99-
RC_READ_SQUEAKS = 75
100-
RC_WRITE_SHARED_ARRAY = 76
101-
RC_READ_SHARED_ARRAY = 77
102-
RC_CAN_TRANSFER_CHEESE = 78
103-
RC_TRANSFER_CHEESE = 79
104-
RC_THROW_RAT = 80
105-
RC_CAN_THROW_RAT = 81
106-
RC_DROP_RAT = 82
107-
RC_CAN_DROP_RAT = 83
108-
RC_CAN_CARRY_RAT = 84
109-
RC_CARRY_RAT = 85
110-
RC_DISINTEGRATE = 86
111-
RC_RESIGN = 87
112-
RC_SET_INDICATOR_STRING = 88
113-
RC_SET_INDICATOR_DOT = 89
114-
RC_SET_INDICATOR_LINE = 90
115-
RC_SET_TIMELINE_MARKER = 91
116-
RC_CAN_TURN__DIR = 92
117-
ML_DISTANCE_SQUARED_TO = 93
118-
ML_BOTTOM_LEFT_DISTANCE_SQUARED_TO = 94
119-
ML_IS_WITHIN_DISTANCE_SQUARED = 95
120-
ML_IS_WITHIN_DISTANCE_SQUARED__LOC_INT_DIR_DOUBLE = 96
121-
ML_IS_WITHIN_DISTANCE_SQUARED__LOC_INT_DIR_DOUBLE_BOOLEAN = 97
122-
ML_IS_ADJACENT_TO = 98
123-
ML_DIRECTION_TO = 99
124-
UT_GET_ALL_TYPE_LOCATIONS = 100
125-
LOG = 101
126-
THROW_GAME_ACTION_EXCEPTION = 102
127-
THROW_EXCEPTION = 103
94+
RC_PICK_UP_CHEESE__LOC_INT = 70
95+
RC_CAN_ATTACK = 71
96+
RC_CAN_ATTACK__LOC_INT = 72
97+
RC_ATTACK = 73
98+
RC_ATTACK__LOC_INT = 74
99+
RC_SQUEAK = 75
100+
RC_READ_SQUEAKS = 76
101+
RC_WRITE_SHARED_ARRAY = 77
102+
RC_READ_SHARED_ARRAY = 78
103+
RC_CAN_TRANSFER_CHEESE = 79
104+
RC_TRANSFER_CHEESE = 80
105+
RC_THROW_RAT = 81
106+
RC_CAN_THROW_RAT = 82
107+
RC_DROP_RAT = 83
108+
RC_CAN_DROP_RAT = 84
109+
RC_CAN_CARRY_RAT = 85
110+
RC_CARRY_RAT = 86
111+
RC_DISINTEGRATE = 87
112+
RC_RESIGN = 88
113+
RC_SET_INDICATOR_STRING = 89
114+
RC_SET_INDICATOR_DOT = 90
115+
RC_SET_INDICATOR_LINE = 91
116+
RC_SET_TIMELINE_MARKER = 92
117+
RC_CAN_TURN__DIR = 93
118+
ML_DISTANCE_SQUARED_TO = 94
119+
ML_BOTTOM_LEFT_DISTANCE_SQUARED_TO = 95
120+
ML_IS_WITHIN_DISTANCE_SQUARED = 96
121+
ML_IS_WITHIN_DISTANCE_SQUARED__LOC_INT_DIR_DOUBLE = 97
122+
ML_IS_WITHIN_DISTANCE_SQUARED__LOC_INT_DIR_DOUBLE_BOOLEAN = 98
123+
ML_IS_ADJACENT_TO = 99
124+
ML_DIRECTION_TO = 100
125+
UT_GET_ALL_TYPE_LOCATIONS = 101
126+
LOG = 102
127+
THROW_GAME_ACTION_EXCEPTION = 103
128+
THROW_EXCEPTION = 104
128129

129130

130131
class CrossPlayObjectType(Enum):

engine/src/crossplay_python/battlecode26/wrappers.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ def on_the_map(loc: MapLocation) -> bool:
243243
return _wait(_m.RC_ON_THE_MAP, [loc])
244244

245245
@staticmethod
246-
def pick_up_cheese(loc: MapLocation) -> None:
247-
_wait(_m.RC_PICK_UP_CHEESE, [loc])
246+
def pick_up_cheese(loc: MapLocation, amount: int = ...) -> None:
247+
if amount is ...:
248+
_wait(_m.RC_PICK_UP_CHEESE, [loc])
249+
else:
250+
_wait(_m.RC_PICK_UP_CHEESE__LOC_INT, [loc, amount])
248251

249252
@staticmethod
250253
def place_cat_trap(loc: MapLocation) -> None:
@@ -341,11 +344,15 @@ def sense_robot_at_location(loc: MapLocation) -> RobotInfo:
341344
@staticmethod
342345
def set_indicator_dot(loc: MapLocation, r: int, g: int, b: int) -> None:
343346
_wait(_m.RC_SET_INDICATOR_DOT, [loc, r, g, b])
344-
347+
345348
@staticmethod
346349
def set_indicator_string(text: str) -> None:
347350
_wait(_m.RC_SET_INDICATOR_STRING, [text])
348-
351+
352+
@staticmethod
353+
def set_indicator_line(startLoc: MapLocation, endLoc: MapLocation, r: int, g: int, b: int) -> None:
354+
_wait(_m.RC_SET_INDICATOR_LINE, [startLoc, endLoc, r, g, b])
355+
349356
@staticmethod
350357
def set_timeline_marker(text: str, r: int, g: int, b: int) -> None:
351358
_wait(_m.RC_SET_TIMELINE_MARKER, [text, r, g, b])

engine/src/crossplay_python/python_docs.md

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

44
## Getting Started
55

@@ -228,7 +228,11 @@ class RobotController:
228228
def on_the_map(loc: MapLocation) -> bool:
229229
pass
230230

231-
def pick_up_cheese(loc: MapLocation) -> None:
231+
def pick_up_cheese(loc: MapLocation, amount: int = ...) -> None:
232+
"""
233+
Calling this function with only the first argument makes the rat
234+
pick up the maximum amount of cheese possible.
235+
"""
232236
pass
233237

234238
def place_cat_trap(loc: MapLocation) -> None:
@@ -296,6 +300,9 @@ class RobotController:
296300
def set_indicator_string(text: str) -> None:
297301
pass
298302

303+
def set_indicator_line(startLoc: MapLocation, endLoc: MapLocation, r: int, g: int, b: int) -> None:
304+
pass
305+
299306
def set_timeline_marker(text: str, r: int, g: int, b: int) -> None:
300307
pass
301308

@@ -467,7 +474,7 @@ class TrapType(Enum):
467474
"""
468475
RAT_TRAP = (30, 50, 20, 15, 25, 2)
469476
CAT_TRAP = (10, 100, 20, 10, 10, 2)
470-
NONE = (0, 0, 0, 0, 0, 0, 0)
477+
NONE = (0, 0, 0, 0, 0, 0)
471478

472479
def ordinal(self) -> int:
473480
"""

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.5',
29+
version='1.2.1',
3030
)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public class GameConstants {
6161
/** The amount of cheese each team starts with. */
6262
public static final int INITIAL_TEAM_CHEESE = 2500;
6363

64+
/** The number of rounds after a backstab after which cat traps are disabled. */
65+
public static final int CAT_TRAP_ROUNDS_AFTER_BACKSTAB = 100;
66+
6467
/** The maximum number of rat kings that a team can have. */
6568
public static final int MAX_NUMBER_OF_RAT_KINGS = 5;
6669

@@ -219,7 +222,7 @@ public class GameConstants {
219222
public static final int DIG_DIRT_CHEESE_COST = 5;
220223

221224
/** The cheese cost to place a tile of dirt */
222-
public static final int PLACE_DIRT_CHEESE_COST = 3;
225+
public static final int PLACE_DIRT_CHEESE_COST = 0;
223226

224227

225228
// *********************************

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,18 @@ public interface RobotController {
792792
*/
793793
void pickUpCheese(MapLocation loc) throws GameActionException;
794794

795+
/**
796+
* Picks up the (non-negative) specified amount of cheese
797+
* from the given location.
798+
*
799+
* @param loc the location to pick up cheese from
800+
* @param pickUpAmount the amount of cheese to pick up
801+
* @throws GameActionException
802+
*
803+
* @battlecode.doc.costlymethod
804+
*/
805+
void pickUpCheese(MapLocation loc, int pickUpAmount) throws GameActionException;
806+
795807
// ****************************
796808
// ***** ATTACK / HEAL ********
797809
// ****************************

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
public enum UnitType {
44
// health, size, visionConeRadiusSquared, visionConeAngle, actionCooldown, movementCooldown, bytecodeLimit
55
BABY_RAT(100, 1, 20, 90, 10, 10, 17500),
6-
RAT_KING(500, 3, 25, 360, 10, 40, 20000),
6+
RAT_KING(600, 3, 25, 360, 10, 40, 20000),
77
CAT(4000, 2, 17, 180, 30, 20, 17500);
88

99
// amount of health robot initially starts with

engine/src/main/battlecode/crossplay/CrossPlay.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,14 @@ private JsonNode processMessage(CrossPlayMessage message, boolean init) throws G
510510
return nodeFactory.nullNode();
511511
}
512512

513+
case RC_PICK_UP_CHEESE__LOC_INT: {
514+
checkParams(message, 2);
515+
MapLocation loc = parseLocNode(message.params().get(0));
516+
int cheeseAmount = message.params().get(1).asInt();
517+
this.processingRobot.pickUpCheese(loc, cheeseAmount);
518+
return nodeFactory.nullNode();
519+
}
520+
513521
case RC_PLACE_CAT_TRAP: {
514522
checkParams(message, 1);
515523
MapLocation loc = parseLocNode(message.params().get(0));

engine/src/main/battlecode/crossplay/CrossPlayMethod.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public enum CrossPlayMethod {
7676
RC_REMOVE_CAT_TRAP,
7777
RC_CAN_PICK_UP_CHEESE,
7878
RC_PICK_UP_CHEESE,
79+
RC_PICK_UP_CHEESE__LOC_INT,
7980
RC_CAN_ATTACK,
8081
RC_CAN_ATTACK__LOC_INT,
8182
RC_ATTACK,

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public class GameWorld {
2323
* Whether we're running.
2424
*/
2525
protected boolean running = true;
26-
protected boolean isCooperation = true;
26+
private boolean isCooperation = true;
27+
private int backstabRound = -1;
28+
private Team backstabber = null;
2729

2830
protected final IDGenerator idGenerator;
2931
protected final GameStats gameStats;
@@ -401,6 +403,25 @@ public boolean isCooperation() {
401403
return this.isCooperation;
402404
}
403405

406+
public int getRoundsSinceBackstab() {
407+
if (this.isCooperation) {
408+
return 0;
409+
} else {
410+
return this.currentRound - this.backstabRound;
411+
}
412+
}
413+
414+
public boolean catTrapsAllowed(Team team) {
415+
return this.isCooperation || (this.getRoundsSinceBackstab() <=
416+
GameConstants.CAT_TRAP_ROUNDS_AFTER_BACKSTAB && this.backstabber != team);
417+
}
418+
419+
public void backstab(Team backstabber) {
420+
this.isCooperation = false;
421+
this.backstabRound = this.currentRound;
422+
this.backstabber = backstabber;
423+
}
424+
404425
public boolean getWall(MapLocation loc) {
405426
return this.walls[locationToIndex(loc)];
406427
}
@@ -601,13 +622,14 @@ public void triggerTrap(Trap trap, InternalRobot robot) {
601622
TrapType type = trap.getType();
602623

603624
robot.setMovementCooldownTurns(type.stunTime);
625+
604626
if (type == TrapType.CAT_TRAP && robot.getType().isCatType()) {
605627
this.teamInfo.addDamageToCats(trap.getTeam(), Math.min(type.damage, robot.getHealth()));
606628
}
607629

608630
if (trap.getType() != TrapType.CAT_TRAP) {
609631
// initiate backstab
610-
this.isCooperation = false;
632+
backstab(robot.getTeam().opponent());
611633
}
612634

613635
matchMaker.addTrapTriggerAction(trap.getId(), loc, triggeringTeam, type);
@@ -807,7 +829,7 @@ public boolean setWinnerIfKilledAllRatKings() {
807829
* @return whether all cats dead
808830
*/
809831
public boolean setWinnerifAllCatsDead() {
810-
if (this.getNumCats() == 0 && this.isCooperation) { // only end game if no more cats in cooperation mode
832+
if (this.getNumCats() == 0 && this.isCooperation()) { // only end game if no more cats in cooperation mode
811833
// find out which team won via points
812834
if (setWinnerIfMorePoints())
813835
return true;
@@ -1134,7 +1156,7 @@ public void destroyRobot(int id, boolean fromException, boolean fromDamage) {
11341156
// check win
11351157
if (robot.getType() == UnitType.RAT_KING && this.getTeamInfo().getNumRatKings(robot.getTeam()) == 0) {
11361158
checkWin(robotTeam);
1137-
} else if (this.isCooperation && robot.getType() == UnitType.CAT && this.getNumCats() == 0) {
1159+
} else if (this.isCooperation() && robot.getType() == UnitType.CAT && this.getNumCats() == 0) {
11381160
checkWin(robotTeam);
11391161
}
11401162
}

0 commit comments

Comments
 (0)