relative density option publish

This commit is contained in:
1brucben
2025-04-27 20:28:47 +02:00
parent 3773fef255
commit 641be0bbb4
3 changed files with 19 additions and 2 deletions
+1
View File
@@ -480,6 +480,7 @@ export interface Game extends GameMap {
executeNextTick(): GameUpdates;
setWinner(winner: Player | Team, allPlayersStats: AllPlayersStats): void;
config(): Config;
averageDefenseDensity(): number;
// Units
units(...types: UnitType[]): Unit[];
+13
View File
@@ -714,6 +714,19 @@ export class GameImpl implements Game {
stats(): Stats {
return this._stats;
}
averageDefenseDensity(): number {
let totalTroops = 0;
let totalTiles = 0;
for (const player of this.players()) {
if (!player.isAlive()) continue;
totalTroops += player.troops();
totalTiles += player.numTilesOwned();
}
if (totalTiles === 0) {
return 1; // safe fallback to prevent division by 0
}
return totalTroops / totalTiles;
}
}
// Or a more dynamic approach that will catch new enum values: