Have more questions? Join our Discord

Randomness and determinism

Rng

All randomness comes from the rng that setup and apply_action receive. No seat can predict its draws.

Method Answers
rng.below(bound) a u32 from 0 to bound - 1. Panics when bound is 0.
rng.roll(sides) a u32 from 1 to sides, like a die.
rng.shuffle(&mut slice) shuffles a slice in place.

To shuffle a space's pieces, use table.shuffle(space_id, rng), which also records the movement.

A step that draws from Rng ends the seat's decision, whatever its intent (Offers, intents and decisions). The board shows its result only after Boardweaver applies it.

Determinism

The same state, action and seed must always give the same result. A draft step shows on the board before Boardweaver applies it. When the two results differ, the player sees the move change after making it.

  • Keep everything in the state. The game functions take no self, and the build refuses static and thread_local.
  • Iterate in a fixed order. Use BTreeMap and BTreeSet, or a Vec. The order of a HashMap or HashSet can differ between two runs of the same game logic.
  • Draw only from the rng you receive. The game logic has no clock, no files and no other source of randomness.