Skip to content

Commit 3f03458

Browse files
committed
CodeRabbit suggestion implemented: Guard against empty borders to prevent crashes; filter candidates with territory.
1 parent 8861e7a commit 3f03458

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/core/execution/utils/BotBehavior.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -269,20 +269,20 @@ export class BotBehavior {
269269
}
270270

271271
selectNearestIslandEnemy() {
272-
const allPlayers = this.game.players();
273-
const filteredPlayers = allPlayers.filter(
274-
(p) =>
275-
// Don't spam boats into players that are more than twice as large as us
276-
p.troops() <= this.player.troops() * 2 &&
277-
!this.player.isFriendly(p) &&
278-
p !== this.player,
279-
);
272+
const myBorder = this.player.borderTiles();
273+
if (myBorder.size === 0) return;
274+
275+
const filteredPlayers = this.game.players().filter((p) => {
276+
if (p === this.player) return false;
277+
if (!p.isAlive()) return false;
278+
if (p.borderTiles().size === 0) return false;
279+
if (this.player.isFriendly(p)) return false;
280+
// Don't spam boats into players more than 2x our troops
281+
return p.troops() <= this.player.troops() * 2;
282+
});
280283

281284
if (filteredPlayers.length > 0) {
282-
const playerCenter = calculateBoundingBoxCenter(
283-
this.game,
284-
this.player.borderTiles(),
285-
);
285+
const playerCenter = calculateBoundingBoxCenter(this.game, myBorder);
286286

287287
const sortedPlayers = filteredPlayers
288288
.map((filteredPlayer) => {

0 commit comments

Comments
 (0)