From bbf72bd14f7f31146c687523aea8fc0aff31bbe1 Mon Sep 17 00:00:00 2001 From: Evan Date: Mon, 3 Feb 2025 12:37:04 -0800 Subject: [PATCH] simply start population calculation --- src/client/graphics/layers/TopBar.ts | 1 - src/core/configuration/DefaultConfig.ts | 8 ++++---- src/core/configuration/DevConfig.ts | 18 ++++++++-------- src/core/execution/ExecutionManager.ts | 11 ++++------ src/core/execution/FakeHumanExecution.ts | 14 ++++--------- src/core/game/Game.ts | 3 ++- src/core/game/GameImpl.ts | 26 ++++++++++++------------ 7 files changed, 36 insertions(+), 45 deletions(-) diff --git a/src/client/graphics/layers/TopBar.ts b/src/client/graphics/layers/TopBar.ts index e689f7e22..c513d7b68 100644 --- a/src/client/graphics/layers/TopBar.ts +++ b/src/client/graphics/layers/TopBar.ts @@ -30,7 +30,6 @@ export class TopBar extends LitElement implements Layer { if (!myPlayer?.isAlive() || this.game?.inSpawnPhase()) { return html``; } - console.log("rendering top bar"); const popRate = this.game.config().populationIncreaseRate(myPlayer) * 10; const maxPop = this.game.config().maxPopulation(myPlayer); const goldPerSecond = this.game.config().goldAdditionRate(myPlayer) * 10; diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index f4556d551..d0735b6dc 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -307,10 +307,10 @@ export class DefaultConfig implements Config { switch (this._gameConfig.difficulty) { case Difficulty.Easy: case Difficulty.Medium: - return 1000; + return 10000 * (playerInfo?.nation?.strength ?? 1); case Difficulty.Hard: case Difficulty.Impossible: - return 2000; + return 20000 * (playerInfo?.nation?.strength ?? 1); } } return 25000; @@ -346,10 +346,10 @@ export class DefaultConfig implements Config { let difficultyMultiplier = 1; switch (this._gameConfig.difficulty) { case Difficulty.Easy: - difficultyMultiplier = 1; + difficultyMultiplier = 0.5; break; case Difficulty.Medium: - difficultyMultiplier = 1.2; + difficultyMultiplier = 0.8; break; case Difficulty.Hard: difficultyMultiplier = 1.5; diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 8aa48b593..640154f51 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -22,16 +22,16 @@ export class DevConfig extends DefaultConfig { // return 100 } - unitInfo(type: UnitType): UnitInfo { - const info = super.unitInfo(type); - const oldCost = info.cost; - info.cost = (p: Player) => oldCost(p) / 1000000000; - return info; - } + // unitInfo(type: UnitType): UnitInfo { + // const info = super.unitInfo(type); + // const oldCost = info.cost; + // info.cost = (p: Player) => oldCost(p) / 1000000000; + // return info; + // } - tradeShipSpawnRate(): number { - return 10; - } + // tradeShipSpawnRate(): number { + // return 10; + // } // percentageTilesOwnedToWin(): number { // return 1 diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index 6851c19e0..94d07e91f 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -155,6 +155,7 @@ export class Executor { fakeHumanExecutions(): Execution[] { const execs = []; for (const nation of this.mg.nations()) { + console.log(`got nation: ${nation.name}`); execs.push( new FakeHumanExecution( this.gameID, @@ -162,13 +163,9 @@ export class Executor { nation.name, PlayerType.FakeHuman, null, - this.random.nextID() - ), - nation.cell, - nation.strength * - this.mg - .config() - .difficultyModifier(this.mg.config().gameConfig().difficulty) + this.random.nextID(), + nation + ) ) ); } diff --git a/src/core/execution/FakeHumanExecution.ts b/src/core/execution/FakeHumanExecution.ts index 795b4c87e..5ddf7bbea 100644 --- a/src/core/execution/FakeHumanExecution.ts +++ b/src/core/execution/FakeHumanExecution.ts @@ -43,12 +43,7 @@ export class FakeHumanExecution implements Execution { private lastEnemyUpdateTick: number = 0; private lastEmojiSent = new Map(); - constructor( - gameID: GameID, - private playerInfo: PlayerInfo, - private cell: Cell, - private strength: number - ) { + constructor(gameID: GameID, private playerInfo: PlayerInfo) { this.random = new PseudoRandom( simpleHash(playerInfo.id) + simpleHash(gameID) ); @@ -77,8 +72,6 @@ export class FakeHumanExecution implements Execution { this.player = this.mg.players().find((p) => p.id() == this.playerInfo.id); if (this.player == null) { return; - } else { - this.player.setTroops(this.player.troops() * this.strength); } } if (this.firstMove) { @@ -522,8 +515,9 @@ export class FakeHumanExecution implements Execution { let tries = 0; while (tries < 50) { tries++; - const x = this.random.nextInt(this.cell.x - delta, this.cell.x + delta); - const y = this.random.nextInt(this.cell.y - delta, this.cell.y + delta); + const cell = this.playerInfo.nation.cell; + const x = this.random.nextInt(cell.x - delta, cell.x + delta); + const y = this.random.nextInt(cell.y - delta, cell.y + delta); if (!this.mg.isValidCoord(x, y)) { continue; } diff --git a/src/core/game/Game.ts b/src/core/game/Game.ts index 4fe660954..4ab38bf60 100644 --- a/src/core/game/Game.ts +++ b/src/core/game/Game.ts @@ -158,7 +158,8 @@ export class PlayerInfo { // null if bot. public readonly clientID: ClientID | null, // TODO: make player id the small id - public readonly id: PlayerID + public readonly id: PlayerID, + public readonly nation?: Nation | null ) {} } diff --git a/src/core/game/GameImpl.ts b/src/core/game/GameImpl.ts index 2ed89e7bc..c0b89002f 100644 --- a/src/core/game/GameImpl.ts +++ b/src/core/game/GameImpl.ts @@ -36,7 +36,7 @@ export function createGame( gameMap: GameMap, miniGameMap: GameMap, nationMap: NationMap, - config: Config, + config: Config ): Game { return new GameImpl(gameMap, miniGameMap, nationMap, config); } @@ -70,7 +70,7 @@ export class GameImpl implements Game { private _map: GameMap, private miniGameMap: GameMap, nationMap: NationMap, - private _config: Config, + private _config: Config ) { this._terraNullius = new TerraNulliusImpl(); this._width = _map.width(); @@ -80,8 +80,8 @@ export class GameImpl implements Game { new Nation( n.name, new Cell(n.coordinates[0], n.coordinates[1]), - n.strength, - ), + n.strength + ) ); } @@ -183,11 +183,11 @@ export class GameImpl implements Game { this, request.requestor() as PlayerImpl, request.recipient() as PlayerImpl, - this._ticks, + this._ticks ); this.alliances_.push(alliance); (request.requestor() as PlayerImpl).pastOutgoingAllianceRequests.push( - request, + request ); this.addUpdate({ type: GameUpdateType.AllianceRequestReply, @@ -199,7 +199,7 @@ export class GameImpl implements Game { rejectAllianceRequest(request: AllianceRequestImpl) { this.allianceRequests = this.allianceRequests.filter((ar) => ar != request); (request.requestor() as PlayerImpl).pastOutgoingAllianceRequests.push( - request, + request ); this.addUpdate({ type: GameUpdateType.AllianceRequestReply, @@ -306,7 +306,7 @@ export class GameImpl implements Game { removeExecution(exec: Execution) { this.execs = this.execs.filter((execution) => execution !== exec); this.unInitExecs = this.unInitExecs.filter( - (execution) => execution !== exec, + (execution) => execution !== exec ); } @@ -459,7 +459,7 @@ export class GameImpl implements Game { } if (!breaker.isAlliedWith(other)) { throw new Error( - `${breaker} not allied with ${other}, cannot break alliance`, + `${breaker} not allied with ${other}, cannot break alliance` ); } if (!other.isTraitor()) { @@ -470,7 +470,7 @@ export class GameImpl implements Game { const alliances = other.alliances().filter((a) => breakerSet.has(a)); if (alliances.length != 1) { throw new Error( - `must have exactly one alliance, have ${alliances.length}`, + `must have exactly one alliance, have ${alliances.length}` ); } this.alliances_ = this.alliances_.filter((a) => a != alliances[0]); @@ -489,7 +489,7 @@ export class GameImpl implements Game { .filter((a) => p1Set.has(a)); if (alliances.length != 1) { throw new Error( - `cannot expire alliance: must have exactly one alliance, have ${alliances.length}`, + `cannot expire alliance: must have exactly one alliance, have ${alliances.length}` ); } this.alliances_ = this.alliances_.filter((a) => a != alliances[0]); @@ -517,7 +517,7 @@ export class GameImpl implements Game { displayMessage( message: string, type: MessageType, - playerID: PlayerID | null, + playerID: PlayerID | null ): void { let id = null; if (playerID != null) { @@ -614,7 +614,7 @@ export class GameImpl implements Game { } bfs( tile: TileRef, - filter: (gm: GameMap, tile: TileRef) => boolean, + filter: (gm: GameMap, tile: TileRef) => boolean ): Set { return this._map.bfs(tile, filter); }