Optimize attack logic by reducing redundant neighbors() and owner() calls

This commit is contained in:
1brucben
2025-04-19 11:27:31 +02:00
parent ce50336b8e
commit 89ae7bc7ef
+4 -3
View File
@@ -240,9 +240,10 @@ export class AttackExecution implements Execution {
const fallbackTiles: { tile: TileRef; weight: number }[] = []; const fallbackTiles: { tile: TileRef; weight: number }[] = [];
const validTiles = this.toConquer.filter((tile) => { const validTiles = this.toConquer.filter((tile) => {
const onBorder = this.mg const neighbors = this.mg.neighbors(tile);
.neighbors(tile) const onBorder = neighbors.some(
.some((t) => this.mg.owner(t) === this._owner); (t) => this.mg.owner(t) === this._owner,
);
return this.mg.owner(tile) === this.target && onBorder; return this.mg.owner(tile) === this.target && onBorder;
}); });
if (validTiles.length === 0) { if (validTiles.length === 0) {