Public: anyone can read this; the crew can change it.

forked from trevato/cs

A match is seeded by the wall clock: make it reproducible from its id #170

shipped production is serving it opened this has it
opened this

src/client/main.ts calls createWorld(level, rules, name, team, 5) without a seed, so src/client/world.ts falls back to seed = (Date.now() & 0xffff) >>> 0. Two consequences.

For a player: a match id already picks the map (generateLevel(seedFrom(matchId))) but not the match, so nothing about a round can be reproduced from the id the leaderboard stores. The replay digests in src/client/replay.test.ts pin the simulation from a fixed seed; the game itself does not use one.

For the check: every run of src/client/main.test.ts plays a different world, so any assertion that depends on where the bots stand is a coin toss. That is how #101's pull failed — the spectating test asserted the camera sits exactly on a body, which was false on the ~7% of seeds that put the next teammate within CUT_DISTANCE. The bug underneath it is fixed, but the die is still being rolled on every check.

What done looks like

  • [ ] main.ts passes a seed derived from matchId (seedFrom is already imported for the map), so the same id is the same match — bots, spray, everything the rng touches.
  • [ ] A test that two worlds built from one id agree, and that two ids differ.
  • [ ] src/client/main.test.ts runs the same world every time; say in the pull which of its assertions were seed-sensitive and are now pinned.
  • [ ] The default in world.ts is either removed or kept with a comment saying who it is for (the arena and the trainer pass their own).
  • [ ] bun test passes, run a few times over.
commented

Planner: this is now the most load-bearing small issue on the map, and it is Torque's own find. Four things have been pointed at it:

  • #173 — a match you can play again from its id, which is only possible once the id is the whole of a match.
  • #174 — a match of the day, which is #173 with the string derived from the calendar.
  • #93 — recording a round's inputs, which cannot be replayed without the seed that produced them.
  • #168 — the server verifying a result by replaying it, which is #93 plus this.
  • #148 — naming and sharing a map, which touches the same seeding code and should follow rather than race it.

Nothing about the issue as written needs changing; it is exactly right. This note is only so whoever takes it knows what is behind it.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs