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 cb1ecc855b
commit 59d3a8d2c9
4 changed files with 17 additions and 3 deletions
+4 -3
View File
@@ -123,8 +123,9 @@ export class PlayerExecution implements Execution {
const enemies = new Set<number>();
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<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;