This is an open-source project bringing unsophisticated billiards physics written in TypeScript to the browser.
Demos run in all major desktop and mobile browsers and use WebGL
- Nine ball ⬀ make a break and share replay link with friends
- Three cushion billiards ⬀ the ultimate test of physics and player (average on both counts). You need the beginner mode ⬀. Try the practice mode ⬀ to drill specific shots.
- Sagu ⬀ Korean four-ball carom game. Try sagu on a 5ft table ⬀.
- Snooker ⬀ we await the first 147 submission to the leaderboard.
- 8-Ball ⬀ try it in Hi-Res mode!
- Play vs the Claw ⬀ and TheFarJaw ⬀.
- Try Multiplayer online pool lobby.
- Try to get on the leaderboard of highest breaks hosted on Vercel.
- Inspect physics and tweak constants using diagrams.
- Set up trick shots and practice ⬀.
- Tune three cushion physics ⬀ and optimise ⬀ parameters
- Parallel parameter ⬀ tuning using Web Workers ⬀.
- Three cushion trainer and sensitivity analysis ⬀ from an excellent fork ⬀ of this project.
- Another great fork for Italian 5 pin.
- Generate SVG and PNG diagrams of shots for blog posts.
- Race again the clock to clear the table in a speedrun.
- Customise your cue and emblem for other players to see
- Sit a hand curated exam to asses your level of play.
- Invite friends and play to win as many games as you can in 30 mins in hourly arenas (lichess.org style)
- Backspin, sidespin and cushion bounces well modeled.
- Presentation using WebGL in any modern browser on mobile, linux, mac or windows.
- Record and playback breaks.
- Two player online mode with nchan nginx server.
- Nine ball, snooker, three cushion and Sagu billiards rules.
- Deploys to GitHub Pages, Vercel and Render with GitHub Actions.
- Runs on and was developed mostly on a potato e.g. Raspberry Pi 4.
You dont, you just play in your browser at billiards.tailuge.workers.dev/lobby
If you prefer, you can install a thin client wrapper:
- Papers on ball mechanics Han 2005 with important corrections by Kiefl.
- cushions, max spin, simulation and constants 1 2 3 4 5
- 3D graphics uses three.js
- Inline LaTeX editor for equations in README.md
Based on Han 2005 paper
where
Based on paper by Alciatore incorporating throw effect due to the small amount of friction between balls. Figures to prove consistency between the code and paper can be found in the Mathavan model validation diagram.
For ball
For ball
Where:
The relative velocity at the point of contact is computed as:
This is based on a paper by Mathavan. Many of the figures from the paper are recreated to confirm correctness.
Slip velocity at cushion contact point I
Slip velocity at table contact point C
Numerical solutions for the centroid velocity of the ball during compression and restitution phases.
Numerical solutions for angular velocity of ball
Work done by the normal force at contact point
The ball is assumed to be bouncing in the +y cushion. Compression phase iterates until
For the restitution phase the iteration continues until the work done is
Some of the Mathavan equations not supplied by the paper were inferred to bridge gaps for a complete numerical solution.
Based on the book Impact Mechanics by Stronge. This analytical model accounts for the compliant nature of cushion deformation and resolves the collision across three slip regimes.
Contact velocity at the cushion contact point:
Regime classification is determined by the ratio
| Regime | Condition |
|---|---|
| Gross slip | |
| Initial stick | |
| Slip-stick-slip | neither of the above |
where
Velocity reconstruction from scalar solver results
Final updates:
nvm use v24.11.0
corepack enable
yarn set version 4.9.1
yarn install
yarn build
yarn gltfpackThis generates artefacts in /dist for prod deployment (e.g. on github static pages)
yarn serveThen open http://localhost:8080/ in your browser to play
yarn test
yarn coverageyarn deps
yarn upgrade -L
yarn prettifyyarn servethen open http://localhost:8080/multi.html to see options, message server is public nchan.
Use mouse, trackpad, touch screen or keyboard:
⇦ ⇨ Aim
Control ⇦ ⇨ Fine aim
⇧ ⇩ Topspin and backspin
Shift ⇦ ⇨ Side spin
Space Hit - hold for more power
A Toggle aim helper
M Masse angle
O Camera view
F Full screen
C Chat
H Help
+ - Camera height
scroll Shot power
dbl click Hit
The physics engine is lightweight and deterministic, making batch rollouts, parameter fitting, and simulation experiments practical:
- Throughput & batch execution: Performs ~500 rollouts/sec on 4 CPU cores in pure TypeScript, scaling across worker threads. Runs in-browser via Web Workers or headlessly via Node.js for parallel batch runs.
- System identification & real-to-sim calibration: Designed for trajectory fitting and physics calibration against recorded real-world shot trajectories. Used to estimate physical parameters such as rolling friction, sliding friction, spin decay, restitution, and cushion deflection.
- Reinforcement learning & planning: Suitable as a fast test environment for RL agents, continuous control, Monte Carlo Tree Search (MCTS), trajectory forecasting, or synthetic dataset generation.
- Parameter optimization: The multi-shot physics optimiser provides a starting point for fitting parameters and exploring the loss landscape against recorded shots.
- Worker interface & headless runs: The Web Worker / simulation research page documents the worker protocol, parallel rollouts, headless Node.js scripts, batch processing, and runtime parameter overrides.
Contributions and experiments are welcome.
July 2018
July 2019
March 2021
August 2023 (mobile)
| top | aim |
|---|---|
Star History
This project is open source and licensed under the GNU General Public License - see the LICENSE file for details. Contributions welcome.