diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 987114028..a6775d812 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -123,8 +123,9 @@ export class PlayerExecution implements Execution { const enemies = new Set(); for (const ref of cluster) { if ( - this.mg.isOceanShore(ref) || - this.mg.neighbors(ref).some((n) => !this.mg.hasOwner(n)) + this.mg.isOceanShore(tile) || + this.mg.isOnEdgeOfMap(tile) || + this.mg.neighbors(tile).some((n) => !this.mg.hasOwner(n)) ) { return false; } @@ -145,7 +146,7 @@ export class PlayerExecution implements Execution { private isSurrounded(cluster: Set): boolean { let enemyTiles = new Set(); for (const tr of cluster) { - if (this.mg.isOceanShore(tr)) { + if (this.mg.isOceanShore(tr) || this.mg.isOnEdgeOfMap(tr)) { return false; } this.mg diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 8b9de9b5b..27c721111 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -89,6 +89,9 @@ export class GameImpl implements Game { this._config.defensePostRange(), ); } + isOnEdgeOfMap(ref: TileRef): boolean { + return this._map.isOnEdgeOfMap(ref); + } owner(ref: TileRef): Player | TerraNullius { return this.playerBySmallID(this.ownerID(ref)); diff --git a/src/core/game/GameMap.ts b/src/core/game/GameMap.ts index d1c079944..8bf1b8ce2 100644 --- a/src/core/game/GameMap.ts +++ b/src/core/game/GameMap.ts @@ -27,6 +27,7 @@ export interface GameMap { setOwnerID(ref: TileRef, playerId: number): void; hasFallout(ref: TileRef): boolean; setFallout(ref: TileRef, value: boolean): void; + isOnEdgeOfMap(ref: TileRef): boolean; isBorder(ref: TileRef): boolean; neighbors(ref: TileRef): TileRef[]; isWater(ref: TileRef): boolean; @@ -185,6 +186,12 @@ export class GameMapImpl implements GameMap { } } + isOnEdgeOfMap(ref: TileRef): boolean { + const x = this.x(ref); + const y = this.y(ref); + return x == 0 || x == this.width() - 1 || y == 0 || y == this.height() - 1; + } + isBorder(ref: TileRef): boolean { return this.neighbors(ref).some( (tr) => this.ownerID(tr) != this.ownerID(ref), diff --git a/src/core/game/GameView.ts b/src/core/game/GameView.ts index ba33c03b3..9370c8895 100644 --- a/src/core/game/GameView.ts +++ b/src/core/game/GameView.ts @@ -240,6 +240,9 @@ export class GameView implements GameMap { }; this.defensePostGrid = new DefenseGrid(_map, _config.defensePostRange()); } + isOnEdgeOfMap(ref: TileRef): boolean { + return this._map.isOnEdgeOfMap(ref); + } public updatesSinceLastTick(): GameUpdates { return this.lastUpdate.updates;