mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-12 04:33:53 +00:00
relative density option publish
This commit is contained in:
@@ -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[];
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user