Skip to content

Commit 3fda251

Browse files
authored
Merge pull request #81 from battlecode/cat_fixes
Cat algo fixes
2 parents f7a8bf5 + 040f11e commit 3fda251

4 files changed

Lines changed: 45 additions & 7 deletions

File tree

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,9 @@ public class GameConstants {
155155
/** The maximum distance from a robot for building traps or dirt */
156156
public static final int BUILD_DISTANCE_SQUARED = 2;
157157

158+
/** The maximum distance from a cat for building traps or dirt, measured from cat center*/
159+
public static final float CAT_BUILD_DISTANCE_SQUARED = 4.5f;
160+
158161
/**
159162
* The maximum distance squared a rat king can build traps or dirt,
160163
* measured from the king's center. All rats (including rat kings)

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,12 @@ public void pounce(int[] delta) {
931931

932932
if (crushedRobot != null && (crushedRobot.getID() != this.ID)) {
933933
// destroy robot
934+
if (crushedRobot.isCarryingRobot()){
935+
InternalRobot carriedRobot = crushedRobot.getRobotBeingCarried();
936+
carriedRobot.addHealth(-carriedRobot.getHealth());
937+
}
934938
crushedRobot.addHealth(-crushedRobot.getHealth());
939+
935940
}
936941
}
937942

@@ -1264,6 +1269,12 @@ else if (this.type == UnitType.CAT) {
12641269

12651270
case CHASE:
12661271

1272+
if (this.catTurns >= 10) {
1273+
this.catTurns = 0;
1274+
this.catState = CatStateType.EXPLORE;
1275+
break;
1276+
}
1277+
12671278
dir = this.gameWorld.getBfsDir(getCatCornerByChirality(), this.catTargetLoc, this.chirality);
12681279

12691280
if (dir == null) {
@@ -1279,6 +1290,7 @@ else if (this.type == UnitType.CAT) {
12791290
for (MapLocation partLoc : partLocs) {
12801291
if (partLoc.distanceSquaredTo(this.catTargetLoc) <= 2) {
12811292
this.catState = CatStateType.SEARCH;
1293+
this.catTurns = 0;
12821294
}
12831295
}
12841296

@@ -1337,6 +1349,7 @@ else if (this.controller.canAttack(nextLoc)) {
13371349
this.catTurnsStuck = 0;
13381350
}
13391351
}
1352+
this.catTurns += 1;
13401353
break;
13411354

13421355
case SEARCH:
@@ -1369,12 +1382,29 @@ else if (this.controller.canAttack(nextLoc)) {
13691382
this.catTargetLoc = rat.getLocation();
13701383
this.catTarget = rat;
13711384
this.catState = CatStateType.ATTACK;
1385+
this.catTurns = 0;
13721386
}
13731387

13741388
this.catTurns += 1;
13751389
break;
13761390

13771391
case ATTACK:
1392+
1393+
if (this.catTurns == 10) {
1394+
if (this.chirality == 0) this.dir = this.dir.rotateRight().rotateRight();
1395+
else this.dir = this.dir.rotateLeft().rotateLeft();
1396+
1397+
this.catTurns += 1;
1398+
break;
1399+
}
1400+
else if (this.catTurns == 11){
1401+
if (this.chirality == 0) this.dir = this.dir.rotateRight().rotateRight();
1402+
else this.dir = this.dir.rotateLeft().rotateLeft();
1403+
1404+
this.catTurns = 0;
1405+
this.catState = CatStateType.EXPLORE;
1406+
break;
1407+
}
13781408

13791409
// step 1: try to find the rat it was attacking, if cannot find it go back to
13801410
// explore
@@ -1391,6 +1421,7 @@ else if (this.controller.canAttack(nextLoc)) {
13911421

13921422
if (!ratVisible) {
13931423
this.catState = CatStateType.EXPLORE;
1424+
this.catTurns = 0;
13941425
break;
13951426
}
13961427

@@ -1463,6 +1494,7 @@ else if (this.controller.canAttack(nextLoc)) {
14631494
this.catTurnsStuck = 0;
14641495
}
14651496
}
1497+
this.catTurns += 1;
14661498
break;
14671499
}
14681500
}

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private void assertCanSenseLocation(MapLocation loc) throws GameActionException
205205
"Target location not within vision range");
206206
}
207207

208-
private void assertCanActLocation(MapLocation loc, int maxRadiusSquared) throws GameActionException {
208+
private void assertCanActLocation(MapLocation loc, float maxRadiusSquared) throws GameActionException {
209209
// assumes maxRadiusSquared <= visionRadiusSquared.
210210
// This handles the angle checking, so we only check distance.
211211
assertCanSenseLocation(loc);
@@ -239,9 +239,8 @@ private void assertCanPlaceDirt(MapLocation loc) throws GameActionException {
239239

240240
assertIsActionReady();
241241
assertIsRobotType(myType);
242-
assertCanActLocation(loc, myType == UnitType.RAT_KING
243-
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
244-
: GameConstants.BUILD_DISTANCE_SQUARED);
242+
float myBuildRadiusSquared = myType == UnitType.RAT_KING ? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED : (myType == UnitType.CAT ? GameConstants.CAT_BUILD_DISTANCE_SQUARED : GameConstants.BUILD_DISTANCE_SQUARED);
243+
assertCanActLocation(loc, myBuildRadiusSquared);
245244

246245
// state checks :
247246
if (this.gameWorld.getTeamInfo().getDirt(this.robot.getTeam()) <= 0)
@@ -263,9 +262,9 @@ private void assertCanRemoveDirt(MapLocation loc) throws GameActionException {
263262

264263
assertIsActionReady();
265264
assertIsRobotType(myType);
266-
assertCanActLocation(loc, myType == UnitType.RAT_KING
267-
? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED
268-
: GameConstants.BUILD_DISTANCE_SQUARED);
265+
266+
float myBuildRadiusSquared = myType == UnitType.RAT_KING ? GameConstants.RAT_KING_BUILD_DISTANCE_SQUARED : (myType == UnitType.CAT ? GameConstants.CAT_BUILD_DISTANCE_SQUARED : GameConstants.BUILD_DISTANCE_SQUARED);
267+
assertCanActLocation(loc, myBuildRadiusSquared);
269268

270269
if ((this.robot.getType().isBabyRatType()
271270
|| this.robot.getType().isRatKingType()) && (this.getAllCheese() < GameConstants.DIG_DIRT_CHEESE_COST))
@@ -847,6 +846,10 @@ public void move(Direction d) throws GameActionException {
847846
if (crushedRobot != null && this.getID() != crushedRobot.getID() && this.getType().isCatType()
848847
&& crushedRobot.getType().isBabyRatType()) {
849848
// kill this rat
849+
if (crushedRobot.isCarryingRobot()){
850+
InternalRobot carriedRobot = crushedRobot.getRobotBeingCarried();
851+
carriedRobot.addHealth(-carriedRobot.getHealth());
852+
}
850853
crushedRobot.addHealth(-crushedRobot.getHealth());
851854
}
852855
// processTrapsAtLocation(newLoc);

specs/specs.pdf

15.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)