Skip to content

Commit 01e9ca3

Browse files
authored
Merge pull request #89 from battlecode/choose-pickup-cheese-amount
overloaded pickup cheese method
2 parents efdfb89 + 1dbd93a commit 01e9ca3

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,21 @@ public void pickUpCheese(MapLocation loc) throws GameActionException {
476476
this.gameWorld.getTeamInfo().addCheeseCollected(this.getTeam(), amountCheeseAvail);
477477
}
478478

479+
@Override
480+
public void pickUpCheese(MapLocation loc, int pickUpAmount) throws GameActionException {
481+
assertCanPickUpCheese(loc);
482+
int amountCheeseAvail = this.gameWorld.getCheeseAmount(loc);
483+
484+
// bound pickup amount above by the amount of cheese available and below by 0
485+
// (can't pick up negative amounts of cheese)
486+
pickUpAmount = Math.max(Math.min(pickUpAmount, amountCheeseAvail), 0);
487+
488+
this.gameWorld.addCheese(loc, -pickUpAmount);
489+
this.robot.addCheese(pickUpAmount);
490+
this.gameWorld.getMatchMaker().addCheesePickUpAction(loc);
491+
this.gameWorld.getTeamInfo().addCheeseCollected(this.getTeam(), pickUpAmount);
492+
}
493+
479494
@Override
480495
public boolean canSenseLocation(MapLocation loc) {
481496
try {

0 commit comments

Comments
 (0)