Randomness
| Context | Randomness rule |
|---|---|
| State-changing hooks | Boardweaver seeds Math.random while running applyActions and preGameInitialization. |
| Read-only hooks and rendering | Derive the answer from state; do not use randomness to decide legal actions or appearance. |
| Reproduction | Preserve the initial position and action sequence when investigating random outcomes. |
Record the outcome in state
Make the random choice while applying an action, then store its result. Every viewer should render that stored result. Recomputing a random choice in a read-only hook can disagree with the authoritative game.
The seeded execution helper restores the surrounding random source after the hook returns. Do not assume independent sandbox sessions continue the same random stream.
Test outcomes
Use a prepared state to exercise a particular result or branch. Test the resulting state and legal actions rather than expecting an arbitrary fresh session to produce the same shuffle.