From c87d0ef3b8165d1a1920972c11ba74a2ca1e528a Mon Sep 17 00:00:00 2001 From: evanpelle Date: Sat, 21 Sep 2024 19:41:21 -0700 Subject: [PATCH] make bot spawner seed gameID --- src/core/configuration/DevConfig.ts | 4 ++-- src/core/execution/BotSpawner.ts | 10 ++++++---- src/core/execution/ExecutionManager.ts | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/core/configuration/DevConfig.ts b/src/core/configuration/DevConfig.ts index 0e4339af3..fe902e24a 100644 --- a/src/core/configuration/DevConfig.ts +++ b/src/core/configuration/DevConfig.ts @@ -19,12 +19,12 @@ export const devConfig = new class extends DefaultConfig { } numBots(): number { - return 400 + return 1 } numFakeHumans(gameID: GameID): number { - return 10 + return 0 } // startTroops(playerInfo: PlayerInfo): number { diff --git a/src/core/execution/BotSpawner.ts b/src/core/execution/BotSpawner.ts index 89bc6b8a7..59ed42fd4 100644 --- a/src/core/execution/BotSpawner.ts +++ b/src/core/execution/BotSpawner.ts @@ -1,14 +1,16 @@ import {Cell, Game, PlayerType, Tile, TileEvent} from "../game/Game"; import {PseudoRandom} from "../PseudoRandom"; -import {SpawnIntent} from "../Schemas"; -import {bfs, dist as dist, manhattanDist} from "../Util"; +import {GameID, SpawnIntent} from "../Schemas"; +import {bfs, dist as dist, manhattanDist, simpleHash} from "../Util"; export class BotSpawner { - private random = new PseudoRandom(123); + private random: PseudoRandom private bots: SpawnIntent[] = []; - constructor(private gs: Game) { } + constructor(private gs: Game, gameID: GameID) { + this.random = new PseudoRandom(simpleHash(gameID)) + } spawnBots(numBots: number): SpawnIntent[] { let tries = 0 diff --git a/src/core/execution/ExecutionManager.ts b/src/core/execution/ExecutionManager.ts index 85eaa3999..ab09f0d41 100644 --- a/src/core/execution/ExecutionManager.ts +++ b/src/core/execution/ExecutionManager.ts @@ -22,7 +22,7 @@ export class Executor { // private random = new PseudoRandom(999) private random: PseudoRandom = null - constructor(private gs: Game, gameID: GameID) { + constructor(private gs: Game, private gameID: GameID) { this.random = new PseudoRandom(simpleHash(gameID)) } @@ -72,7 +72,7 @@ export class Executor { spawnBots(numBots: number): Execution[] { - return new BotSpawner(this.gs).spawnBots(numBots).map(i => this.createExec(i)) + return new BotSpawner(this.gs, this.gameID).spawnBots(numBots).map(i => this.createExec(i)) } fakeHumanExecutions(numFakes: number): Execution[] {