AI Agents Wrote All 301 of Our Games. Tests Are the Hard Part.

engineeringgame-enginestesting

AI agents do most of the work on TrySolitaire. A person sets the goals and decides what ships. More from TrySolitaire Engineering

A chart of the lines of code for one game: Klondike 4,606, the median game with a class of its own 1,001, the median spec game 105, and Limited 74

Measured: November 14, 2026, on the code that runs the site
Games: all 301


For a while, our code held a file named thievesofegypt.js. It described a two-deck Pyramid: you match pairs of cards that add to 13.

Thieves of Egypt is a real game, and it is nothing like that. It is a Forty Thieves game. Ten columns are dealt as a pyramid, 1-3-5-7-9-10-8-6-4-2. You build down in alternating colours, and the stock turns over once. Three published sources agree on it.

An AI agent wrote that file. It was one of 31 that were not live, and most of them described games that do not exist. Files of that kind came with tests, and some came with guides in several languages. Nothing in the code could tell a real game from an invented one.

AI agents wrote every game on TrySolitaire, all 301 of them. They also wrote the engines and the tests that this post describes, and they wrote the post. An agent can write a card game in less than an hour. With the same confidence, it can write a game that nobody has ever played.

So the hard question was never how to write 300 games. It was how to know that a game is right. This post is our answer so far: 233 games of about 100 lines each, and what each one must pass before it ships.


One File, One Game

This is a whole game. It is called Limited, and its file is 74 lines.

The board of Limited, twelve columns of three cards, above the part of its file that makes the game: pileSizes is the deal, canBuildOn is the build rule, and redeals is the number of times the stock turns over. On this deal the four of diamonds can go on the five of diamonds.
The board is a screenshot of the game. The code is the game's file, as it is.

The file starts with the rules in plain words, and where they come from:

// Canonical rules (Morehead & Mott-Smith, "Limited"; Parlett's Forty
// Thieves group): two decks. Twelve tableau columns of three cards, all
// face up. Eight foundations build up in suit from the aces. The
// tableau builds DOWN BY SUIT, strictly one card at a time; an empty
// column takes any single card. The stock deals one card at a time to
// the waste, no redeal. Win: all 104 cards on the foundations.

It ends with the game that it passes to its engine:

super('limited', {
    gameName: 'Limited',
    pileSizes: COLUMN_SIZES,
    // Down by suit, one rank at a time, no wrapping — the
    // family's classic build (Morehead & Mott-Smith).
    canBuildOn: (card, top) =>
        card.suit === top.suit && card.value === top.value - 1,
    redeals: 0,
    layout: LimitedGame.layoutContract
});

Three keys make the game. pileSizes is the deal. canBuildOn is the build rule. redeals is how often the stock turns over. Between the rules and the keys stand nine numbers for the layout, with their arithmetic.

Look at what the file does not have. There is no drag in it, no tap, no undo, no save, no hint and no animation. Play Limited, and you find all of them.


What the 74 Lines Stand On

Five layers drawn as tall as their line counts. Limited, 74 lines, is a thin gold bar on top. Under it: the Forty Thieves engine, 171 lines, used by 40 games; the stock and waste layer, 791 lines, 74 games; the solitaire and column engines, 1,243 lines, 233 games; the base card game, 994 lines, 280 games.
Each layer is as tall as its line count. The gold bar on top is the game.

Limited’s 74 lines stand on 3,199 lines that it shares with its siblings. Each layer holds only what the games above it do the same way.

We did not design these layers first. We measured them. When we wanted a Klondike engine beside the Forty Thieves engine, we compared the two. The Forty Thieves engine was 711 lines then. 483 of them were about the shape of the board: a stock and a waste over columns. Only 73 were about being Forty Thieves. So the shape became a layer of its own, and 74 games stand on it today.

Spider went the other way. It has no waste pile, and it does not build its foundations card by card. Those are the two things that layer is about. So Spider did not become its child. The 210 lines that both needed moved up a layer instead.

A fix that every sibling gets

A shared layer shows its worth when something is wrong in it. Ours was a game that could not end.

Some games let you turn the stock over as often as you like. For those games, “is a card left in the stock?” is always yes. A board with no move left would never be over. For that reason we could not write three games at all: Saratoga, Trigon and Athena.

The answer is in the stock-and-waste layer, and it is a proof, not a guess. When no card on the board can move, only one thing can still change: which card lies on top of the waste. Turning the stock and recycling it is a fixed cycle, so it must come back to a state that it was in before. The layer walks the cycle. If a card that comes to the top can be played, the game is alive. If the cycle repeats first, the game is over.

const seen = new Set();
for (;;) {
    const key = `${stock.length}|${stock.join(',')}|${waste.join(',')}`;
    if (seen.has(key)) { return true; }
    seen.add(key);

    if (stock.length > 0) {
        const count = Math.min(drawCount, stock.length);
        const turned = stock.slice(stock.length - count).reverse();
        stock = stock.slice(0, stock.length - count);
        waste = [...waste, ...turned];
    } else if (waste.length > 0) {
        stock = [...waste].reverse();
        waste = [];
        continue; // a recycle exposes nothing by itself
    } else {
        return true;
    }
    if (playable(waste[waste.length - 1])) { return false; }
}

Saratoga turns three cards at a time. There, the walk also finds the cards that never come to the top. A check that asks only “are cards left?” gets exactly that wrong.

Ten games on this layer turn their stock without limit today. Not one of their files holds a line of this code.


One Board, Four Games, One Line Apart

“A game is a rule set, not a class” is the second decision of our plan, from August 28, 2026. This is what it means in practice.

Four boards of ten columns. Streets: every card face up, build on the other colour. Emperor: the same with three rows face down. Rank and File: the same, and a run of cards moves as one. Number Ten: the same with two rows face down.
Four games from the books, on one engine. Each differs from the one before it by one line.

Streets, Emperor, Rank and File and Number Ten are four games with four names in the books. Here is the whole difference between Emperor and Rank and File, without the comments:

- gameName: 'Emperor',
+ gameName: 'Rank and File',
  pileSizes: COLUMN_SIZES,
  faceDownRows: FACE_DOWN_ROWS,
  canBuildOn: (card, top) =>
      card.color !== top.color && card.value === top.value - 1,
+ movesRuns: true,
  redeals: 0,
- layout: EmperorGame.layoutContract
+ layout: RankAndFileGame.layoutContract

One line of rules. In Emperor you move one card at a time. In Rank and File a run of cards moves as one, and that is a different game to play.

A key must earn its place

A key such as movesRuns is the only way that a game can differ from its family. So we add one only when four things are true:

  1. It unlocks a game that has a name in the books.
  2. It adds, and it changes nothing that exists.
  3. Its default leaves every live game as it is.
  4. We break it on purpose in the first game that uses it, and a test fails.

A game file must not hold behaviour. When a game “fixes up” its family’s deal in code, a key is missing. Storehouse started that way. Its fix became the foundationBase key.


How We Know That a Game Is Right

For a new game, an agent reads the rule sources and writes the sheet, the game file, its test and its guide. Then it runs the gates. A person sets the goals and decides what ships.

Eight steps before a game is live: the sheet with the rule sources quoted; the game file; its own test; the family playthrough; the guide; the wiring; the save; a real browser at seven screen sizes.
The gates do not ask who wrote a game. They ask what it must pass.

Two ideas carry most of the weight.

A test must be able to fail

For each rule, we change the rule on purpose and watch which test fails. Here it is for Limited. We turn its build rule upside down:

- card.suit === top.suit && card.value === top.value - 1,
+ card.suit === top.suit && card.value === top.value + 1,

Then we run its tests:

 × limited-rules.test.js > Limited rules
     > builds down by suit only, and there is NO redeal
   → expected false to be true

 Tests  1 failed | 243 passed (244)

One test fails, and it is the right one. The other 243 pass, and that is the interesting part.

240 of them are the playthrough of the family. It plays hundreds of hinted moves on the broken game and finds nothing wrong. A game where you build upward is still a game. Every card is still accounted for, and undo still works. Only Limited’s own small test knows what Limited is. That is why each game has both.

When a test still passes after we break its rule, the test is empty, and we write it again. That has happened more than once: a trigger for an illegal move, an undo of a count of zero, a check that read fewer games than there were.

A gate finds its own subjects

The save gate and the guide gate do not read a list of games. They take every file that imports an engine. A new game cannot be left off them, because there is no list to leave it off.

Before every push, the whole suite runs: more than 25,000 tests in 700 files.


What Went Wrong Anyway

Silence that looked like success. A check over a list must first prove that the list is not empty, and a probe that could measure nothing must fail. One probe cleared Pyramid of a layout fault. It was counting visible cards, not reading where they were.

Seven games with no styles. The script that wires a new game took one block in the stylesheet as proof that the game was styled. Seven games reached a build without their styles. The gate that should have caught them compared each game with its siblings, and the seven were each other’s siblings. We fixed the script and the gate.

Motion that never ran. Our headless browser reported that the user prefers reduced motion. That turns every animation off, so every motion check passed by doing nothing. The browser check now asks for motion in so many words.

Names without rules. This is the story at the top. The rule now: a file with no source is a name, not a rule set. We write the game again from published sources, and we delete the old file, its test and its translated guides. If a source does not state a rule, the file says “not stated”.


What It Costs

GamesMedian linesAll lines
Spec games on a family engine23310525,373
Games with a class of their own681,00176,708
The engines and their shared layers15 files10,595

A spec game is small because 58% of its lines are comments: the rules, and their sources.

A shared layer cuts both ways. A fault in the column engine is a fault in 219 games at once. That is what the family playthroughs are for. When we move code up a layer, every assertion must stay untouched and green.

68 games are not on an engine. 47 are solitaires that agents wrote as classes of their own, before the engines existed. The other 21 are not solitaire at all: Sudoku, Mahjong, Hearts, 2048.

We did not move the flagships. Klondike is the game that people play most: 64,900 games in September. Its file is 4,606 lines, and it stays as it is. So do Spider and FreeCell. The engines exist to make new games cheap. A game that so many people play moves only in a step of its own, with its own proof, or not at all.

The layout does not reduce to a rule. Each game still carries nine numbers for its layout, and a test holds them against the stylesheet.

Reading comes first. A game with no new key takes about 45 minutes, guide included. Before that comes the sheet: the sources with the rule text quoted, the deal as numbers that add up to the deck, and how the game differs from each game that we have. A second pass tries to prove the sheet wrong from another source. Only a sheet that stands is built.


What We Do Not Know Yet

If you have solved one of these, tell us how.


Follow Along

This is the first post of a series about how the site is built. The next ones:

To get the next post: the engineering section, the RSS feed, or TrySolitaire on LinkedIn.

And the games are there to play:


How We Measured


Published November 14, 2026 | TrySolitaire Blog · Play Free Solitaire