Engineering Deep Dive

Six Games, Three Classic Algorithms: Shipping Real Game AI in Vanilla JS

The games on this site run on three textbook algorithms — the classic game-tree families (far simpler than today’s neural-network 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  ·  Updated September 2026

6
AI games
3
classic algorithms
0
dependencies
0
losses in 1,200 games

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. How its reach-rate climbs with search depth — and where the compute cost explodes — is measured in the depth benchmark. 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 a couple of milliseconds or less 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

92.8% 2048 64% 4096 10.8% 8192 lkforge.com

Reach rate drops per doubling: 92.8% of games get a 2048 tile, 64% get to 4096, and 10.8% of the 250 games reached 8192. That's a corner-snake heuristic search with probability-threshold pruning running at ~2 ms/move — good enough to be genuinely hard to beat, not good enough to solve the game.

2048 game board where the AI solver has built a 2048 tile in the bottom-right corner, illustrating the corner-snake strategy
The site's expectimax solver on AI Auto-Play, paused the moment it built the 2048 tile — pinned in the bottom-right corner, exactly as the corner-snake heuristic intends. This is the 92.8% outcome, the left bar of the ladder above.

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. Deeper measured studies on the individual game AIs: 2048 by search depth, Go by MCTS playouts, four negamax engines by depth, and how often Minesweeper forces a guess.

Play Against the Search

Try to beat full-depth minimax at tic-tac-toe, or watch expectimax chase a corner-snake board in 2048.

Play Tic-Tac-Toe → Watch 2048's AI →

Common questions

What algorithms do the LK Forge games use?

Three classical, deterministic game-tree algorithms — not a language model. Tic-tac-toe uses minimax with alpha-beta pruning, the 2048 solver uses expectimax over the random tile spawns, and Color Lines uses breadth-first search (BFS) for pathfinding. All of them run entirely in your browser.

How often does the 2048 AI reach the 2048 tile?

In a 250-game headless self-play benchmark, LK Forge's expectimax solver reached the 2048 tile in 92.8% of games and the 4096 tile in 64%; 10.8% of the 250 games reached 8192. It averages about 2 ms per move.

Is the tic-tac-toe AI really unbeatable?

Across 1,200 self-play games the full-depth minimax player lost zero. The honest caveat is that a shallower search is not automatically safe: capping the depth at 2 still won 87% of 200 games but also lost 2 of them. Only full-depth search removes losses entirely.

Does a deeper search always mean a stronger AI?

No. Against a random opponent, a depth-2 tic-tac-toe search won 87% of games yet still lost 2 of 200, while full-depth search lost none. Extra depth buys guarantees, not just a higher win rate.

How fast is the Color Lines pathfinding?

BFS answers a hint query in about 0.006 ms. 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.

Were these numbers measured or estimated?

Measured. Every figure comes from running the shipped game code headlessly with a seeded random number generator, and the harness is public and re-runnable — the link is in the post.