From 49ff20ce9a7372c80d1c87b73092b74a735105d5 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 17 Feb 2025 19:58:57 -0800 Subject: [PATCH] don't lose territory if surrounded at edge of map --- src/core/execution/PlayerExecution.ts | 3 ++- src/core/game/GameImpl.ts | 3 +++ src/core/game/GameMap.ts | 7 +++++++ src/core/game/GameView.ts | 3 +++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 11e191632..4dcaaf40a 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -124,6 +124,7 @@ export class PlayerExecution implements Execution { for (const tile of cluster) { if ( 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;