leaderboard shows percentage non-fallout tiles owned

This commit is contained in:
Evan
2025-01-24 09:09:31 -08:00
parent 7a2f4210ed
commit 7325cfc7e6
5 changed files with 39 additions and 27 deletions
+3 -1
View File
@@ -53,12 +53,14 @@ export class Leaderboard extends LitElement implements Layer {
const sorted = this.game.playerViews()
.sort((a, b) => b.numTilesOwned() - a.numTilesOwned())
const numTilesWithoutFallout = this.game.numLandTiles() - this.game.numTilesWithFallout()
this.players = sorted
.slice(0, 5)
.map((player, index) => ({
name: player.displayName(),
position: index + 1,
score: formatPercentage(player.numTilesOwned() / this.game.numLandTiles()),
score: formatPercentage(player.numTilesOwned() / numTilesWithoutFallout),
gold: renderNumber(player.gold()),
isMyPlayer: player == myPlayer,
player: player
+9 -13
View File
@@ -31,26 +31,22 @@ export class DevConfig extends DefaultConfig {
}
// percentageTilesOwnedToWin(): number {
// return 1
// return 10
// }
// populationIncreaseRate(player: Player): number {
// return this.maxPopulation(player)
// }
// tradeShipSpawnRate(): number { // return 10
// boatMaxDistance(): number {
// return 5000
// }
boatMaxDistance(): number {
return 5000
}
numBots(): number {
return 0
}
spawnNPCs(): boolean {
return false
}
// numBots(): number {
// return 0
// }
// spawnNPCs(): boolean {
// return false
// }
}
+2 -10
View File
@@ -43,8 +43,6 @@ export class GameImpl implements Game {
private updates: GameUpdates = createGameUpdatesMap()
private _numTilesWithFallout = 0
constructor(
private _map: GameMap,
private miniGameMap: GameMap,
@@ -62,9 +60,6 @@ export class GameImpl implements Game {
))
}
numTilesWithFallout(): number {
return this._numTilesWithFallout
}
owner(ref: TileRef): Player | TerraNullius {
return this.playerBySmallID(this.ownerID(ref))
@@ -99,7 +94,6 @@ export class GameImpl implements Game {
if (this._map.hasFallout(tile)) {
return
}
this._numTilesWithFallout++
this._map.setFallout(tile, value)
this.addUpdate({
type: GameUpdateType.Tile,
@@ -341,10 +335,7 @@ export class GameImpl implements Game {
owner._tiles.add(tile)
owner._lastTileChange = this._ticks
this.updateBorders(tile)
if (this._map.hasFallout(tile)) {
this._numTilesWithFallout--
this._map.setFallout(tile, false)
}
this._map.setFallout(tile, false)
this.addUpdate({
type: GameUpdateType.Tile,
update: this.toTileUpdate(tile)
@@ -511,6 +502,7 @@ export class GameImpl implements Game {
bfs(tile: TileRef, filter: (gm: GameMap, tile: TileRef) => boolean): Set<TileRef> { return this._map.bfs(tile, filter) }
toTileUpdate(tile: TileRef): bigint { return this._map.toTileUpdate(tile) }
updateTile(tu: TileUpdate): TileRef { return this._map.updateTile(tu) }
numTilesWithFallout(): number { return this._map.numTilesWithFallout() }
}
// Or a more dynamic approach that will catch new enum values:
+24 -3
View File
@@ -43,9 +43,13 @@ export interface GameMap {
toTileUpdate(tile: TileRef): bigint
updateTile(tu: TileUpdate): TileRef
numTilesWithFallout(): number
}
export class GameMapImpl implements GameMap {
private _numTilesWithFallout = 0
private readonly terrain: Uint8Array; // Immutable terrain data
private readonly state: Uint16Array; // Mutable game state
private readonly width_: number;
@@ -74,6 +78,9 @@ export class GameMapImpl implements GameMap {
this.terrain = terrainData;
this.state = new Uint16Array(width * height);
}
numTilesWithFallout(): number {
return this._numTilesWithFallout
}
ref(x: number, y: number): TileRef {
if (!this.isValidCoord(x, y)) {
@@ -145,10 +152,17 @@ export class GameMapImpl implements GameMap {
}
setFallout(ref: TileRef, value: boolean): void {
const existingFallout = this.hasFallout(ref)
if (value) {
this.state[ref] |= 1 << GameMapImpl.FALLOUT_BIT;
if (!existingFallout) {
this._numTilesWithFallout++
this.state[ref] |= 1 << GameMapImpl.FALLOUT_BIT;
}
} else {
this.state[ref] &= ~(1 << GameMapImpl.FALLOUT_BIT);
if (existingFallout) {
this._numTilesWithFallout--
this.state[ref] &= ~(1 << GameMapImpl.FALLOUT_BIT);
}
}
}
@@ -253,8 +267,15 @@ export class GameMapImpl implements GameMap {
const tileRef = Number(tu >> 16n);
const state = Number(tu & 0xFFFFn);
// Update the state for this tile
const existingFallout = this.hasFallout(tileRef)
this.state[tileRef] = state;
const newFallout = this.hasFallout(tileRef)
if (existingFallout && !newFallout) {
this._numTilesWithFallout--
}
if (!existingFallout && newFallout) {
this._numTilesWithFallout++
}
return tileRef;
}
+1
View File
@@ -299,4 +299,5 @@ export class GameView implements GameMap {
bfs(tile: TileRef, filter: (gm: GameMap, tile: TileRef) => boolean): Set<TileRef> { return this._map.bfs(tile, filter) }
toTileUpdate(tile: TileRef): bigint { return this._map.toTileUpdate(tile) }
updateTile(tu: TileUpdate): TileRef { return this._map.updateTile(tu) }
numTilesWithFallout(): number { return this._map.numTilesWithFallout() }
}