Six Games, Three Classic Algorithms: Shipping Real Game AI in Vanilla JS
The six games on this site run on three textbook algorithms — the same families behind competitive chess engines. The engineering story isn't the algorithms; it's getting them correct and frame-fast in a browser tab with zero dependencies.
· 7 min read · all numbers from re-runnable headless benchmarks
The Three Algorithms
Minimax with alpha-beta pruning runs the tic-tac-toe opponent. Full-depth search is what makes the "unbeatable" claim true: 1,200 self-play games — 1,000 against a random player, 200 against a perfect copy of itself — produced zero losses. The pruning is what makes full depth affordable in a browser: at the opening move, plain minimax explores 549,945 nodes against 36,528 with alpha-beta, a 93% cut, and the move itself resolves in about 0.3 ms. The internals are written up separately in the minimax writeup and the game-theory piece.
Expectimax with a corner-snake heuristic drives the 2048 solver. Unlike tic-tac-toe, 2048 has a random tile spawn after every move, so the search has to average over outcomes instead of assuming a deterministic opponent — that's the "expect" in expectimax. It runs at roughly 0.5 ms per move. What that search buys is covered in how the solver works and the corner-snake strategy.
Breadth-first search answers the one question Color Lines actually needs solved: is there a clear path between two cells on a 9×9 board. It's the cheapest of the three algorithms and it shows — about 0.006 ms per query. The pathfinding details are in the BFS writeup.
Why Vanilla JS, Zero Dependencies
None of the three engines needs a framework, a game-AI library, or a build step to be fast. Each is a search function operating on a small board representation — an array for tic-tac-toe and 2048, a grid graph for Lines — and the searches above run in well under a millisecond on plain, dependency-free JavaScript. There's no bundle to audit for a supply-chain vulnerability and no runtime to update when a library ships a breaking release.
That also matches how the games are served. Every one of the six is static: HTML, CSS, and JS shipped as files, deployed to Cloudflare's edge, no backend, no database, nothing running server-side to keep a game AI responsive. The search that decides the AI's move happens entirely on the device already rendering the board.
What We Actually Measured
None of the numbers above are marketing rounding. They came from running the shipped production code headlessly, hundreds of times, and counting outcomes.
2048 reach-rate ladder, 250 self-play games
Reach rate drops fast per doubling: 69.6% of games get a 2048 tile, 30% get to 4096, and none of the 250 sampled games reached 8192. That's the honest ceiling of a corner-snake heuristic search running at ~0.5 ms/move — good enough to be genuinely hard to beat, not good enough to solve the game.
Color Lines: across 2,000 sampled boards, a clear path between a random source and target existed 52.4% of the time, with a mean length of 6.87 cells when one was found. BFS doesn't need to be clever about that — it needs to be correct and cheap, and at 0.006 ms per query it's both.
Tic-tac-toe: zero losses across 1,200 games is the headline, but the honest footnote is that deeper search isn't automatically stronger against a random opponent. Capping the search at depth 2 instead of the full depth 9 still won 87% of 200 games — and also lost 2 of them. Full-depth search is what removes the losses entirely; a shallow search only looks unbeatable until it isn't.
Every number here comes from the shipped game code run headlessly, and the harness is public and seeded — run it yourself → to reproduce the node counts and the depth-2 losses.
This is one piece of a larger build. The full sprint that produced this site — 26 repositories, 1,549 commits, 335 pages in 29 days — is covered in 26 Repos in 29 Days With an AI Pipeline.
Related reading: how each of these numbers is proven before it ships is in How We Benchmark a Game AI, and the per-move performance that keeps the search under a single frame is in Search Algorithms Inside One Browser Tab.
Play Against the Search
Try to beat full-depth minimax at tic-tac-toe, or watch expectimax chase a corner-snake board in 2048.