Skip to content

Commit ace35df

Browse files
committed
prevent cat bfs null direction error, allow pounce escape if cat is completely trapped by walls
1 parent b156bc9 commit ace35df

1 file changed

Lines changed: 21 additions & 5 deletions

File tree

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

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ public int[] canPounce(MapLocation loc) {
880880
// pounce distnace
881881
boolean isWithinPounceDistance = (this.getLocation()
882882
.bottomLeftDistanceSquaredTo(loc) <= GameConstants.CAT_POUNCE_MAX_DISTANCE_SQUARED);
883-
if (!this.gameWorld.isPassable(loc) || !isWithinPounceDistance) {
883+
if (!this.gameWorld.getGameMap().onTheMap(loc) || !this.gameWorld.isPassable(loc) || !isWithinPounceDistance) {
884884
return null;
885885
}
886886

@@ -1189,11 +1189,10 @@ else if (this.type == UnitType.CAT) {
11891189
this.controller.turn(random);
11901190
}
11911191
catch (GameActionException e){}
1192-
11931192
}
11941193
}
1195-
else{
1196-
// cat not stuck! let's set our eyes on the next waypoint
1194+
else if (this.catTurnsStuck == 0){
1195+
// cat not stuck and ready to move! let's set our eyes on the next waypoint
11971196
MapLocation waypoint = catWaypoints[currentWaypoint];
11981197

11991198
if (getCatCornerByChirality().equals(waypoint)) {
@@ -1248,10 +1247,24 @@ else if (this.type == UnitType.CAT) {
12481247
}
12491248
}
12501249
}
1250+
1251+
// try pouncing out
1252+
if (isStuck){
1253+
// try pouncing
1254+
int[] pounceTraj = null;
1255+
MapLocation twoTilesAway = this.getCatCornerByChirality().add(dir).add(dir);
1256+
pounceTraj = canPounce(twoTilesAway);
1257+
if (canMoveCooldown() && pounceTraj != null) {
1258+
this.pounce(pounceTraj);
1259+
isStuck = false;
1260+
}
1261+
}
12511262

1263+
// give up
12521264
if (isStuck) {
12531265
this.catTurnsStuck += 1;
1254-
} else {
1266+
}
1267+
else {
12551268
this.catTurnsStuck = 0;
12561269
}
12571270
}
@@ -1325,6 +1338,9 @@ else if (this.type == UnitType.CAT) {
13251338
// if pounce failed, try moving in the direction of the target
13261339
else{
13271340
dir = this.gameWorld.getBfsDir(getCatCornerByChirality(), this.catTargetLoc, this.chirality);
1341+
if (dir == null || dir == Direction.CENTER) {
1342+
dir = this.location.directionTo(this.catTargetLoc);
1343+
}
13281344
if (this.controller.canMove(this.dir)) {
13291345
try {
13301346
this.controller.move(this.dir);

0 commit comments

Comments
 (0)