Puddle: from a web prototype to a native iPhone game
Puddle started as a one-file web prototype: drag blocks onto a grid, wall in an empty space, and rain fills it. The puddle washes away every block it touches.
The first job was to move the rules into Swift without changing a single outcome, because the daily board has to give everyone the same pieces.
How we kept the two versions identical
- The web build exports its 41 piece shapes to a JSON file, so Swift loads the same list in the same order.
- The random number generator is ported bit for bit, so the same seed deals the same pieces.
- Node prints thousands of deals, puddles and scores from the web build, and Swift must produce byte-identical JSON. 22 tests check it.
The one-ulp bug
One test failed by the smallest possible amount. JavaScript's Math.log1p(2) and Apple's differ in the last bit. The fix: a small table of the JavaScript values, so the dealer ranks hands exactly as the web build does.