aboutsummaryrefslogtreecommitdiff
path: root/rng
AgeCommit message (Collapse)AuthorFilesLines
2026-04-22Migrate remaining relative imports to @hollowdark/*; strip //-comments and ↵Bobby1-6/+3
doc references, JSDoc-only
2026-04-22Drop all barrel index.ts files; imports target leaf files directlyBobby1-2/+0
2026-04-22Use relative imports for same-directory siblings; split utils into foldersBobby2-3/+3
Two related cleanups landed together because they touch the same pattern: 1. Intra-module imports now use relative paths rather than the module's own path alias. rng/seeded.ts imports from './derive', not 'rng/derive'; time/gameTime.ts from './calendar', not 'time/calendar'; the utils barrel from './result' etc. This matches rules/01-code-style.md: "Relative imports only for same-directory siblings." The alias form is reserved for imports *between* modules — how external callers refer to a module's public surface. (The TS language server in the IDE had trouble resolving the self- aliased form even though svelte-check accepted it; this change removes the ambiguity.) 2. utils/ is now folder-per-concept. Each utility owns a directory with its files broken up into small pieces: utils/result/ types, constructors, predicates, map, unwrap utils/assert/ assert, assert-never, assert-defined utils/equal/ deep utils/types/ brand, deep-readonly, element-of, json, non-empty-array utils/log/ log utils/index.ts re-exports from each subfolder via the barrel. External callers import from 'utils' unchanged; internal references are relative. One reason to prefer folders over flat files here is headroom — when a concept grows, new files sit alongside their siblings inside the concept's folder rather than crowding the utils/ root. No API changes. All 128 tests still green.
2026-04-22Implement seeded PRNG with deterministic sub-RNG derivationBobby3-0/+154
rng/ is the load-bearing primitive for simulation determinism (ARCHITECTURE.md §26). All gameplay randomness routes through createRNG; Math.random is forbidden in gameplay code by ESLint. rng/derive.ts xmur3 string hash + deriveSeed(parentSeed, label), stable across processes and runs rng/seeded.ts SeededRNG interface, mulberry32 implementation, next / nextInt / nextBool / pick / weightedPick / sub rng/index.ts public re-exports Sub-RNG derivation is the key technical move: seeding a child with hash(parent_seed + label) lets NPCs' trajectories be regenerated deterministically from their identity tuple alone — which is how Tier 3 NPCs stay off-disk until the player needs them. 29 determinism tests in tests/determinism/rng.test.ts cover: same seed → same sequence, sub-RNG independence from parent consumption, sub-order matters, input validation, and a byte-level inline snapshot that locks the PRNG output for seed "hollowdark". The snapshot is load-bearing — if mulberry32 or xmur3 changes, every existing save diverges, so treat a snapshot break as a migration concern, not an update-the-snapshot fix.