Fix bot/nation player ID collisions causing missing players 🔧#3354
Fix bot/nation player ID collisions causing missing players 🔧#3354
Conversation
WalkthroughA PRNG seed adjustment in BotSpawner offsets the hash-based seed by 2 to prevent ID collisions between bot identities and nation/human identities generated from the same sequence. Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/core/execution/BotSpawner.ts (1)
16-18: Good fix for the ID collision bug.The seed offset of
+2correctly separates BotSpawner's PRNG sequence from GameRunner (+0) and ExecutionManager (+1). The comment is clear and explains the "why" well.One small note for future maintenance: the offset scheme is now spread across three files with no central list. If another component needs unique IDs later, a developer might accidentally pick a used offset. Consider adding a brief comment here (or in a shared location) listing all current offsets:
// Seed offsets: // +0: GameRunner (human/nation IDs) // +1: ExecutionManager // +2: BotSpawnerThis is optional — the current fix is correct and solves the immediate problem.
,
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/execution/BotSpawner.ts` around lines 16 - 18, Add a brief comment near BotSpawner's PRNG seed initialization to document the seed offset scheme so future authors don't reuse offsets; reference the existing line where BotSpawner sets this.random = new PseudoRandom(simpleHash(gameID) + 2) and add a short list noting "+0: GameRunner (human/nation IDs), +1: ExecutionManager, +2: BotSpawner" (or place that same comment in a shared location referenced by GameRunner and ExecutionManager) so offsets are centrally visible and maintained.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/core/execution/BotSpawner.ts`:
- Around line 16-18: Add a brief comment near BotSpawner's PRNG seed
initialization to document the seed offset scheme so future authors don't reuse
offsets; reference the existing line where BotSpawner sets this.random = new
PseudoRandom(simpleHash(gameID) + 2) and add a short list noting "+0: GameRunner
(human/nation IDs), +1: ExecutionManager, +2: BotSpawner" (or place that same
comment in a shared location referenced by GameRunner and ExecutionManager) so
offsets are centrally visible and maintained.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d4dc6568-a7be-4a92-918d-7a1639aae8e9
📒 Files selected for processing (1)
src/core/execution/BotSpawner.ts
Description:
BotSpawner used the same PRNG seed (simpleHash(gameID)) as createGameRunner, causing bot IDs to collide with nation IDs. When a bot's SpawnExecution found a nation with the same ID via hasPlayer(), it silently reused that nation instead of creating a new player - resulting in far fewer players than configured (e.g. ~670 instead of 800 with 400 bots + 400 nations) with no console warnings.
Offsets the BotSpawner seed by +2 to avoid the shared PRNG sequence (matching the +1 pattern already used by Executor).
Please complete the following:
Please put your Discord username so you can be contacted if a bug or regression is found:
FloPinguin