Skip to content

Commit 6f1c334

Browse files
committed
add python support for picking up arbitrary amount of cheese, and make cheese picked up by rat king be cheese transferred
1 parent 01e9ca3 commit 6f1c334

7 files changed

Lines changed: 68 additions & 41 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: 5 additions & 2 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:

engine/src/crossplay_python/python_docs.md

Lines changed: 6 additions & 2 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:

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/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/RobotControllerImpl.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,12 @@ public void pickUpCheese(MapLocation loc) throws GameActionException {
473473
this.gameWorld.addCheese(loc, -amountCheeseAvail);
474474
this.robot.addCheese(amountCheeseAvail);
475475
this.gameWorld.getMatchMaker().addCheesePickUpAction(loc);
476-
this.gameWorld.getTeamInfo().addCheeseCollected(this.getTeam(), amountCheeseAvail);
476+
this.gameWorld.getTeamInfo().addCheeseCollected(getTeam(), amountCheeseAvail);
477+
478+
if (getType() == UnitType.RAT_KING) {
479+
this.gameWorld.getMatchMaker().addCheeseTransferAction(robot.getID(), amountCheeseAvail);
480+
this.gameWorld.getTeamInfo().addCheeseTransferred(getTeam(), amountCheeseAvail);
481+
}
477482
}
478483

479484
@Override
@@ -488,7 +493,12 @@ public void pickUpCheese(MapLocation loc, int pickUpAmount) throws GameActionExc
488493
this.gameWorld.addCheese(loc, -pickUpAmount);
489494
this.robot.addCheese(pickUpAmount);
490495
this.gameWorld.getMatchMaker().addCheesePickUpAction(loc);
491-
this.gameWorld.getTeamInfo().addCheeseCollected(this.getTeam(), pickUpAmount);
496+
this.gameWorld.getTeamInfo().addCheeseCollected(getTeam(), pickUpAmount);
497+
498+
if (getType() == UnitType.RAT_KING) {
499+
this.gameWorld.getMatchMaker().addCheeseTransferAction(robot.getID(), pickUpAmount);
500+
this.gameWorld.getTeamInfo().addCheeseTransferred(getTeam(), pickUpAmount);
501+
}
492502
}
493503

494504
@Override

0 commit comments

Comments
 (0)