[Low] [Bug] Procedural guardian names duplicated across different floors #376
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Steps to reproduce:
Expected: Each guardian should have a unique name
Actual: Several guardians share the same or very similar names:
Likely cause: The procedural guardian naming algorithm in
guardian-procedural.tsgenerates names based on element combinations, but doesn't check for uniqueness across floors.Stores involved:
data/guardian-procedural.tsStarting investigation. Bug: procedural guardian names duplicated across different floors. Reading guardian-procedural.ts to understand the naming algorithm.
Root Cause Identified
The
generateGuardianName()function uses(floor + i) % prefixes.lengthfor prefix andMath.floor(floor / 10) % titles.lengthfor title. Both cycle with periods that create collisions:floor % 5)This means single-element guardians at floors 170/370, 180/380, 210/420 etc. get identical names.
Examples verified:
Fix Approach
Add a floor-offset modifier to the prefix selection in
generateGuardianName— use(floor + i * 3 + Math.floor(floor / 50))instead of(floor + i)to shift the prefix cycle so the same elements at different 100-floor cycles get different prefixes. This keeps names deterministic but unique per floor.Fix Complete ✅
Changes
src/lib/game/data/guardian-encounters.ts— ModifiedgenerateGuardianName()to add acycleOffset = Math.floor(floor / 50)that shifts prefix selection so the same elements at different 100-floor ranges produce different names. For multi-element names, the title is also shifted bycycleOffset.src/lib/game/__tests__/guardian-names-unique.test.ts— New regression test with 7 test cases.Verification
Specific fixes for reported collisions
Commit:
b68cc94