Change BorderTiles from Array to Set (#230)

Changed border constant from Array to Set, to avoid potential
duplicates.
This commit is contained in:
ByGoalZ
2025-03-13 14:05:10 +01:00
committed by GitHub
parent a1d0c87232
commit 8124651382
+5 -5
View File
@@ -73,12 +73,12 @@ export class BotExecution implements Execution {
this.neighborsTerraNullius = false;
}
const border = Array.from(this.bot.borderTiles())
.flatMap((t) => this.mg.neighbors(t))
.filter((t) => this.mg.hasOwner(t) && this.mg.owner(t) != this.bot);
const border = new Set(
this.bot.borderTiles().flatMap((t) => this.mg.neighbors(t)));
const enemies = Array.from(border).filter(
(t) => this.mg.hasOwner(t) && this.mg.owner(t) !== this.bot);
if (border.length == 0) {
return;
if (enemies.length === 0) return;
}
const toAttack = border[this.random.nextInt(0, border.length)];