don't lose territory if surrounded at edge of map

This commit is contained in:
Evan
2025-02-17 19:58:57 -08:00
parent 5d0e0561ca
commit 49ff20ce9a
4 changed files with 15 additions and 1 deletions
+2 -1
View File
@@ -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<TileRef>): boolean {
let enemyTiles = new Set<TileRef>();
for (const tr of cluster) {
if (this.mg.isOceanShore(tr)) {
if (this.mg.isOceanShore(tr) || this.mg.isOnEdgeOfMap(tr)) {
return false;
}
this.mg
+3
View File
@@ -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));
+7
View File
@@ -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),
+3
View File
@@ -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;