From d2a8b487644c56e838605d9c429284aff8ef6e65 Mon Sep 17 00:00:00 2001 From: evanpelle Date: Thu, 29 Aug 2024 20:24:50 -0700 Subject: [PATCH] remove playerconfig --- TODO.txt | 2 +- src/client/ClientGame.ts | 12 ++++++------ src/core/configuration/Config.ts | 3 --- src/core/configuration/DefaultConfig.ts | 13 +++---------- src/core/configuration/DevConfig.ts | 9 ++------- src/core/execution/AttackExecution.ts | 5 ++--- src/core/execution/BotExecution.ts | 1 - src/core/execution/PlayerExecution.ts | 4 ++-- src/core/execution/SpawnExecution.ts | 3 +-- src/core/execution/UpdateNameExecution.ts | 1 - 10 files changed, 17 insertions(+), 36 deletions(-) diff --git a/TODO.txt b/TODO.txt index d7134491c..e35e227bb 100644 --- a/TODO.txt +++ b/TODO.txt @@ -55,7 +55,7 @@ * make bot spawn better DONE 8/28/2024 * make UX for attacking TerraNullius by boat better DONE 8/29/2024 * make bot territory less funky (more likely attack neighbors with larger border) DONE 8/29/2024 -* PERF: use hierarchical a* search for boats +* give boats limit for how far they can go * PERF: precompute spawns * PERF: load terrain map async * PERF: enable CDN diff --git a/src/client/ClientGame.ts b/src/client/ClientGame.ts index d53ae0baf..44c04b742 100644 --- a/src/client/ClientGame.ts +++ b/src/client/ClientGame.ts @@ -212,10 +212,10 @@ export class ClientGame { // Attack Player if (tile.isLand()) { if (this.myPlayer.sharesBorderWith(tile.owner())) { - this.sendAttackIntent(targetID, cell, this.gs.config().player().attackAmount(this.myPlayer, owner)) + this.sendAttackIntent(targetID, cell, this.gs.config().attackAmount(this.myPlayer, owner)) } else if (owner.isPlayer()) { console.log('going to send boat') - this.sendBoatAttackIntent(targetID, cell, this.gs.config().player().boatAttackAmount(this.myPlayer, owner)) + this.sendBoatAttackIntent(targetID, cell, this.gs.config().boatAttackAmount(this.myPlayer, owner)) } } return @@ -229,7 +229,7 @@ export class ClientGame { const neighbors = Array.from(bfs(tile, and((r, t) => t.isLand(), dist(100)))); for (const n of neighbors) { if (this.myPlayer.borderTiles().has(n)) { - this.sendAttackIntent(targetID, cell, this.gs.config().player().attackAmount(this.myPlayer, owner)) + this.sendAttackIntent(targetID, cell, this.gs.config().attackAmount(this.myPlayer, owner)) return } } @@ -239,9 +239,9 @@ export class ClientGame { .filter(t => !t.hasOwner()) .sort((a, b) => manhattanDist(tile.cell(), a.cell()) - manhattanDist(tile.cell(), b.cell())) if (tn.length > 0) { - this.sendBoatAttackIntent(targetID, tn[0].cell(), this.gs.config().player().boatAttackAmount(this.myPlayer, owner)) + this.sendBoatAttackIntent(targetID, tn[0].cell(), this.gs.config().boatAttackAmount(this.myPlayer, owner)) } else { - this.sendAttackIntent(targetID, cell, this.gs.config().player().attackAmount(this.myPlayer, owner)) + this.sendAttackIntent(targetID, cell, this.gs.config().attackAmount(this.myPlayer, owner)) } } @@ -255,7 +255,7 @@ export class ClientGame { .filter(t => !t.hasOwner()) .sort((a, b) => manhattanDist(tile.cell(), a.cell()) - manhattanDist(tile.cell(), b.cell())) if (tn.length > 0) { - this.sendBoatAttackIntent(targetID, tn[0].cell(), this.gs.config().player().boatAttackAmount(this.myPlayer, owner)) + this.sendBoatAttackIntent(targetID, tn[0].cell(), this.gs.config().boatAttackAmount(this.myPlayer, owner)) } } } diff --git a/src/core/configuration/Config.ts b/src/core/configuration/Config.ts index 627475879..8bab76f23 100644 --- a/src/core/configuration/Config.ts +++ b/src/core/configuration/Config.ts @@ -16,15 +16,12 @@ export function getConfig(): Config { export interface Config { theme(): Theme; - player(): PlayerConfig turnIntervalMs(): number gameCreationRate(): number lobbyLifetime(): number numBots(): number numSpawnPhaseTurns(): number -} -export interface PlayerConfig { startTroops(playerInfo: PlayerInfo): number troopAdditionRate(player: Player): number attackTilesPerTick(attacker: Player, defender: Player | TerraNullius, numAdjacentTilesWithEnemy: number): number diff --git a/src/core/configuration/DefaultConfig.ts b/src/core/configuration/DefaultConfig.ts index c03c52458..bb94c361a 100644 --- a/src/core/configuration/DefaultConfig.ts +++ b/src/core/configuration/DefaultConfig.ts @@ -1,6 +1,6 @@ import {Player, PlayerInfo, TerraNullius, Tile} from "../Game"; import {within} from "../Util"; -import {Config, PlayerConfig, Theme} from "./Config"; +import {Config, Theme} from "./Config"; import {pastelTheme} from "./PastelTheme"; import {vintageTheme} from "./VintageTheme"; @@ -13,9 +13,6 @@ export class DefaultConfig implements Config { numBots(): number { return 250 } - player(): PlayerConfig { - return defaultPlayerConfig - } turnIntervalMs(): number { return 100 } @@ -26,9 +23,6 @@ export class DefaultConfig implements Config { return 20 * 1000 } theme(): Theme {return pastelTheme;} -} - -export class DefaultPlayerConfig implements PlayerConfig { attackLogic(attacker: Player, defender: Player | TerraNullius, tileToConquer: Tile): {attackerTroopLoss: number; defenderTroopLoss: number; tilesPerTickUsed: number} { if (defender.isPlayer()) { @@ -78,8 +72,7 @@ export class DefaultPlayerConfig implements PlayerConfig { return Math.min(player.troops() + toAdd, max) } - } -export const defaultConfig = new DefaultConfig() -export const defaultPlayerConfig = new DefaultPlayerConfig() \ No newline at end of file + +export const defaultConfig = new DefaultConfig() \ No newline at end of file diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 5d82278d4..310ff4afb 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -1,6 +1,5 @@ import {PlayerInfo} from "../Game"; -import {PlayerConfig} from "./Config"; -import {DefaultConfig, DefaultPlayerConfig, defaultPlayerConfig} from "./DefaultConfig"; +import {DefaultConfig} from "./DefaultConfig"; export const devConfig = new class extends DefaultConfig { numSpawnPhaseTurns(): number { @@ -15,15 +14,11 @@ export const devConfig = new class extends DefaultConfig { turnIntervalMs(): number { return 100 } - player(): PlayerConfig { - return devPlayerConfig - } + numBots(): number { return 250 } -} -export const devPlayerConfig = new class extends DefaultPlayerConfig { startTroops(playerInfo: PlayerInfo): number { if (playerInfo.isBot) { return 5000 diff --git a/src/core/execution/AttackExecution.ts b/src/core/execution/AttackExecution.ts index 5c436e41a..49ad6827e 100644 --- a/src/core/execution/AttackExecution.ts +++ b/src/core/execution/AttackExecution.ts @@ -2,7 +2,6 @@ import {PriorityQueue} from "@datastructures-js/priority-queue"; import {Cell, Execution, MutableGame, MutablePlayer, PlayerID, TerraNullius, Tile} from "../Game"; import {PseudoRandom} from "../PseudoRandom"; import {manhattanDist} from "../Util"; -import {Config, PlayerConfig} from "../configuration/Config"; export class AttackExecution implements Execution { private active: boolean = true; @@ -79,7 +78,7 @@ export class AttackExecution implements Execution { return } - let numTilesPerTick = this.mg.config().player().attackTilesPerTick(this._owner, this.target, this.numTilesWithEnemy) + let numTilesPerTick = this.mg.config().attackTilesPerTick(this._owner, this.target, this.numTilesWithEnemy) if (this.targetCell != null) { numTilesPerTick /= 2 } @@ -114,7 +113,7 @@ export class AttackExecution implements Execution { badTiles++ continue } - const {attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed} = this.mg.config().player().attackLogic(this._owner, this.target, tileToConquer) + const {attackerTroopLoss, defenderTroopLoss, tilesPerTickUsed} = this.mg.config().attackLogic(this._owner, this.target, tileToConquer) numTilesPerTick -= tilesPerTickUsed this.troops -= attackerTroopLoss if (this.target.isPlayer()) { diff --git a/src/core/execution/BotExecution.ts b/src/core/execution/BotExecution.ts index c70c739ac..49c3d3292 100644 --- a/src/core/execution/BotExecution.ts +++ b/src/core/execution/BotExecution.ts @@ -1,4 +1,3 @@ -import {Config, PlayerConfig} from "../configuration/Config"; import {Cell, Execution, MutableGame, MutablePlayer, Player, PlayerID, PlayerInfo, TerraNullius} from "../Game" import {PseudoRandom} from "../PseudoRandom" import {simpleHash} from "../Util"; diff --git a/src/core/execution/PlayerExecution.ts b/src/core/execution/PlayerExecution.ts index 2fcd9e2e6..43d40d07e 100644 --- a/src/core/execution/PlayerExecution.ts +++ b/src/core/execution/PlayerExecution.ts @@ -1,4 +1,4 @@ -import {Config, PlayerConfig} from "../configuration/Config" +import {Config} from "../configuration/Config" import {Execution, MutableGame, MutablePlayer, PlayerID} from "../Game" export class PlayerExecution implements Execution { @@ -22,7 +22,7 @@ export class PlayerExecution implements Execution { if (ticks < this.config.numSpawnPhaseTurns()) { return } - this.player.setTroops(this.config.player().troopAdditionRate(this.player)) + this.player.setTroops(this.config.troopAdditionRate(this.player)) } owner(): MutablePlayer { diff --git a/src/core/execution/SpawnExecution.ts b/src/core/execution/SpawnExecution.ts index aca172119..899db5201 100644 --- a/src/core/execution/SpawnExecution.ts +++ b/src/core/execution/SpawnExecution.ts @@ -1,4 +1,3 @@ -import {Config, PlayerConfig} from "../configuration/Config" import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo} from "../Game" import {BotExecution} from "./BotExecution" import {PlayerExecution} from "./PlayerExecution" @@ -37,7 +36,7 @@ export class SpawnExecution implements Execution { return } - const player = this.mg.addPlayer(this.playerInfo, this.mg.config().player().startTroops(this.playerInfo)) + const player = this.mg.addPlayer(this.playerInfo, this.mg.config().startTroops(this.playerInfo)) getSpawnCells(this.mg, this.cell).forEach(c => { player.conquer(this.mg.tile(c)) }) diff --git a/src/core/execution/UpdateNameExecution.ts b/src/core/execution/UpdateNameExecution.ts index bc87ab20b..364ed7b29 100644 --- a/src/core/execution/UpdateNameExecution.ts +++ b/src/core/execution/UpdateNameExecution.ts @@ -1,4 +1,3 @@ -import {Config, PlayerConfig} from "../configuration/Config" import {Execution, MutableGame, MutablePlayer, PlayerID} from "../Game" import {ClientID} from "../Schemas"