A 3D curling game: a five-club ladder against a computer rival, ends of eight stones, real scoring and the hammer rule, coins and a pro shop. Plain Three.js for the view; the physics, rules and rival are a few hundred lines of plain TypeScript. No models or image files: stones, ice, arena, crowd, banners and boards are all generated in code.
Architecture
core/ is pure TypeScript with no engine imports and is unit-tested with Vitest: sim.ts (the sheet physics), rules.ts (scoring, throw order, hammer, style bonuses), ai.ts (the rival), venues.ts (the ladder, the shop and the coin formula).world.ts is the Three.js view: it builds the arena, copies stone positions from the simulation each frame and draws effects and the camera. It owns the renderer, the loop and every GPU resource.index.tsx wires input, the HTML interface (scoreboard, house view, gauges, menus and results are all HTML and SVG) and the match flow.
Physics
- A stone is a disc on a 2D sheet in metres. Friction is a constant deceleration (about 0.09 m/s², so a 2.25 m/s release stops on the tee 28 m away); the venue multiplies it for slow or keen ice, and frost patches multiply it again where they lie.
- Curl is a sideways acceleration perpendicular to the direction of travel, proportional to the stone's turn and growing as the stone slows (
k · spin / (0.55 v + 0.25)), so the stone runs straight early and breaks late like a real one. Sweeping lowers the friction by up to 16 % (times the broom's power) and cuts the curl by nearly half. A draft is a constant sideways push; bumpy patches add a small deterministic wobble. - Stone-on-stone contacts are equal-mass collisions along the line of centres with a restitution of 0.92, so a head-on hit nearly stops the shooter and sends the target on; overlaps are pushed apart evenly. A struck stone picks up a little turn from a glancing contact.
- Out of play: touching the side boards, fully past the back line, or (for the delivered stone) stopping short of the far hog line without touching another stone.
- Fixed 1/60 s steps, no randomness, so a throw always ends the same; real curling is slow, so the view runs the sheet 2.3 times faster than life (a draw takes about 11 s).
Rival
The rival copies the sheet and tries 300 throws (ten weights from a light draw to a hard hit, fifteen lines, both turns), runs each to rest and scores the board: the projected points of the end, how close each stone sits to the button, and guards while stones remain. It plays the best one with its venue's error (a normal spread on weight and line) and, on the easy clubs, sometimes settles for a lesser idea. The tests check that a perfect rival draws near the button and removes a lone stone on it.
Game
- Ends of eight stones, four each; the team without the hammer throws first. The team with the closest stone scores one point per stone closer than the opponent's best; the scoring team gives up the hammer, a blank end keeps it. A tie after the last end plays an extra end.
- Upgrades are five tracks with three tiers each: broom power (sweep strength), sweep stamina (seconds of sweeping per throw), curl control (how much drafts, frost and bumps still push your stone), path sight (how much of the predicted path is drawn) and the weight gauge (a guard mark, a stop readout, then a stop marker on the ice). Two one-throw perks (Steady hand, Hot broom) and three stone finishes. Every club has one challenge (button draw, takeout, steal, double, win by three) that pays a bonus once.
- Transitions: a camera fly-in over the arena with a venue title card on every match (tap skips), an end title and a camera glide back to the hack between ends, scoreboard numbers flip in, confetti and a crowd cheer on a win. The rival's throws can be fast-forwarded.
- Coins: the club's prize for a win (plus 5 per point of margin over one), 10 for a loss, and style bonuses for takeouts, double takeouts, button draws and stolen ends. They buy two broom upgrades (stronger sweep), two path sights (the first third or two thirds of the predicted path) and three stone finishes. Progress, coins, upgrades and settings live in
localStorage (hammerstone:v1), read defensively.
View
- The ice is a planar
Reflector under a translucent pebbled skin (canvas-painted droplets as colour and bump map), so stones and lights mirror softly in it; the low-quality tier drops the mirror. House rings and lines are flat meshes just under the skin. - Stones are a lathe profile with a speckled granite texture, a polished striking band, and a tube-geometry gooseneck handle; the player's finish changes granite and handle. Blob shadows keep the cost low.
- The camera has five modes (clubhouse orbit, delivery, chase that rises over the house, settled house view, end-of-end orbit) and pushes in low on a hard hit while the sheet drops to slow motion for half a second. Ice spray and broom frost are one point cloud with a small shader.
- Under reduced motion there is no slow motion, push-in, shake, spray or crowd jump, and the interface does not animate.