Question
How can each shape on the board maintain a consistent, deterministic initial rotation value even after the application is closed and reopened?
Short Answer
This consistency was achieved by replacing the use of the global Math.random() function with a seeded random generator (this.rng) and assigning each shape a deterministic rotation value during board creation.
Previously, each shape’s rotation was initialized using a non-deterministic random value, meaning that every time the app restarted, shapes on the same level appeared with different initial rotations. In the updated implementation, the board creation process now includes a step where each cell’s rotation is derived from the same deterministic seed as the level generation logic.
Instead of relying on:
this.rotation = EdgeUtils.fromIndex(Math.floor(Math.random() * 4))
the new structure integrates seeded randomness:
const rotationIndex = Math.floor(this.rng.nextFloat() * 4)
board.cells[row][col].rotation = rotationIndex
and then initializes a consistent base orientation using:
this.rotation = EdgeUtils.fromIndex(0)
This ensures that each shape has a predictable initial rotation tied to its position and level seed. As a result, if the user closes and reopens the app, the same shapes will appear with the same orientations they had originally—restoring the deterministic layout without visual inconsistency.
Applicable Scenarios
- When deterministic level layouts are required, ensuring that the same board appears identically after app restarts.
- To maintain consistent visual state across sessions for reproducible gameplay and debugging.
- In procedural generation systems where rotation or position randomness should remain stable for a given seed.
- For games or puzzles where shape orientation affects gameplay and must remain synchronized with saved progress.
Top comments (0)