From 812465138262747e7b7d97ac36b046bc8ef1eb85 Mon Sep 17 00:00:00 2001 From: ByGoalZ <168545120+ByGoalZ@users.noreply.github.com> Date: Thu, 13 Mar 2025 14:05:10 +0100 Subject: [PATCH] Change BorderTiles from Array to Set (#230) Changed border constant from Array to Set, to avoid potential duplicates. --- src/core/execution/BotExecution.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index 956fb90a8..4f6f84cf3 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -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)];