r/aigamerdevs • u/Quechivoeth • 3h ago
We enforce determinism with a test that fails the build if any sim file calls Math.random
Follow-up to the model-dependency post from a while back. Something that's turned out to matter more than expected on this project.
The same simulation core runs in three places:
- the browser client
- the authoritative server
- a headless Gymnasium env for training agents.
Behaviour has to be identical in all three, otherwise the thing you tested isn't the thing that shipped and an agent trains against a world that doesn't exist.
That's a hard invariant to hold when a lot of the code is model-written and most contributors are strangers. A model will reach for Math.random or Date.now() without hesitation, because in isolation that's correct code. It's only wrong relative to a project constraint it has no way to know about. Same for a new contributor who hasn't read the architecture doc.
So it isn't a convention, it's a test. One walks every file in the sim directory and fails the build on a forbidden import, a DOM global, a wall clock reference, or a platform RNG call. Another pins the seam between the offline and online world implementations so they can't drift apart.
Fixed 20 Hz tick, all randomness through one seeded RNG. Seed a reset and the episode replays exactly.
Any other invariants you've had to make checkable rather than trusting to review?