Is Mahjong Solitaire Always Solvable? What a Solver Found

By Dawid Siedlarz · · 8 min read

Play Mahjong free →

Short answer: No. When the tiles are dealt at random, some Mahjong solitaire boards cannot be cleared even by a player who can see every tile: Michiel de Bondt's solver found 2.95% of 10 million random deals of the classic 144-tile turtle layout unwinnable. Some computer versions, ours included, build every board so that it has a solution. But a solvable board is not a won game: in our test a player who picked a random matching pair each turn still got stuck on 30% to 45% of boards.

Anyone who has stared at a Mahjong board with twenty tiles left and no free pair has asked the same thing: was this ever possible? The question has two parts. First, does the deal have any clearing order at all? Second, will a real player find it, move by move? The answers are very different, and we measured both on our own Mahjong with the game's own rules.

How many random deals can't be won?

The best measurement we found comes from the mathematician Michiel de Bondt, who wrote a fast solver and described it in "Solving Mahjong Solitaire boards with peeking" (arXiv, 2012). "Peeking" means the solver may look at every tile, including the ones underneath, so it answers the first question: does any clearing order exist? He dealt the tiles at random onto the layouts of the open-source game Xmahjongg and solved each board. For the standard turtle layout he scanned 10,000,000 boards, about 40 hours of computing, and found 2.95% that cannot be cleared; his solver page gives "between 2.95 and 2.96 percent". Other layouts were scanned 100,000 times each, and the shape matters enormously: 0.62% of "Theater" deals are dead, 32% of "Bridge" and 47% of "Ox", and two layouts, "Hourglass" and "Papillon", could never be cleared at all.

So on the classic layout roughly one random deal in 34 is lost before the first click. That figure has not, as far as we know, been checked independently, but it is a published method with a large sample, which is more than the "most games are winnable" claims you will find on forums.

Our own experiment: 900 random deals on three layouts

Our Mahjong is smaller than the turtle: Easy has 48 tiles in two layers, Medium 72 tiles in three, Hard 96 tiles in four, always four copies of each tile. We wrote a short program (tools/mahjong-solvability.js in our site repository) that loads the game's own code, including its rule for when a tile is free (nothing on top and the left or right side open), and ran two tests with seeded, reproducible deals.

Random deal, exact search (300 deals per level). It shuffled the tiles onto the layout the way a person setting up a physical set would, then searched every clearing order, remembering positions already proved dead. The search had a budget of two million positions per board; a board it could not settle within that budget is counted as "not settled", not guessed.

LayoutTilesClearableProved impossibleNot settled
Easy4899.3%0.7%0%
Medium7292.7%7.0%0.3%
Hard9690.7%0%9.3%

300 random deals per layout, seeds 1-300. "Not settled" means the search hit its budget of 2,000,000 positions; on Hard those 28 boards are probably a mix of clearable and impossible ones, so 90.7% is a lower bound for Hard, not an estimate.

Two things stand out. A flat, wide layout like our Easy is almost never dead, and the Medium layout, which has a three-high pile in the middle, loses 7% of random deals: the layout's shape decides how many deals die, as in de Bondt's spread between layouts. For Hard, the tallest of the three, our search could only say that between 0% and 9.3% of deals are impossible. And proving that a board is impossible is much harder than finding a solution when one exists, because the search has to rule out every order. On Hard that is exactly what ran out of budget.

Why some boards are dead from the start

A board is dead when the tiles you need are locked under each other. The simplest case needs only four tiles. Suppose the last two kinds left are bamboo and dragon, and they sit in two piles of two: pile one has a dragon on a bamboo, pile two has a bamboo on a dragon. The two top tiles are free, but they don't match. Each one you need is underneath the other kind. No order of moves helps, so the board was lost the moment the tiles were placed.

Real dead boards are longer chains of the same idea: copies of one tile buried under copies of another, which are buried under the first. De Bondt's paper proves that even boards made only of tiny isolated piles of three (the forms he writes as "aab" and "abb") are already hard to decide in general. That is why a dead board rarely looks dead until late in the game. Our guide to how to play Mahjong solitaire mentions the everyday version of this: two copies of the same tile in one pile need the other two copies before they can go.

How our game makes sure every board can be cleared

Some computer versions do not deal at random. Ours builds the board backwards: it starts with the full layout, repeatedly picks two tiles that are free right now, gives them the same face and sets them aside, until every position has a face. Playing those pairs in reverse order always clears the board, so no Extensive Harmony board is dead from the start. If the builder ever paints itself into a corner (fewer than two free tiles), it starts again; it tries up to 200 times.

The Shuffle button uses the same builder on the tiles that are left, so a shuffled position is also clearable from where you stand. It costs you: each shuffle takes 60 points off the score, which starts at 1,200 minus one point per second and is then multiplied by 1.5 on Medium and 2.5 on Hard.

Solvable doesn't mean you'll solve it

A guaranteed solution only says that a clearing order exists. To see how often an ordinary player misses it, we let the program play our own (always clearable) boards in three ways:

How pairs are chosenEasyMediumHard
Any matching pair, at random29.5% stuck43.6% stuck44.5% stuck
Lowest tiles first52.5% stuck65.7% stuck77.2% stuck
Highest tiles first36.7% stuck39.8% stuck37.8% stuck

2,000 of our boards per level (seeds 1-2000), every one with a solution. Lowest-first and highest-first take the free matching pair whose tiles sit on the lowest (or highest) layers. Commands: node tools/mahjong-solvability.js 300 for the random deals, node tools/mahjong-solvability.js --players 2000 for this table.

The pattern is clear. Clearing the easy pairs on the bottom layer first is the worst habit: it uses up copies of a tile that you will later need to open a stack. Taking pairs from the highest layers first halves the stuck rate on Hard compared with lowest-first (37.8% against 77.2%) and beats random play on Medium and Hard. On the flat Easy board it is worse than random play, because there is little height to work with. None of the simple rules comes close to zero, though, because the right choice sometimes depends on tiles you can't see yet. When the player gets stuck, the random player still has about 13 tiles left on Easy and about 20 on Medium and Hard.

How hard is Mahjong solitaire for a computer?

Hard enough to have a place in computer science. If every tile is visible, deciding whether a board can be cleared is NP-complete: no known method does it quickly for every possible board, and a fast method would also crack thousands of other famous problems. David Eppstein lists this result for "Shanghai" on his page on the complexity of games and puzzles, and de Bondt's 2012 paper proves it even for the restricted boards of small piles mentioned above. Counting how many solutions a board has is harder still (#P-complete, also on Eppstein's page).

The version you actually play hides the tiles underneath. For that game, Anne Condon, Joan Feigenbaum, Carsten Lund and Peter Shor showed in 1997 that even approximating the best possible chance of winning is PSPACE-hard ("Random Debaters and the Hardness of Approximating Stochastic Functions", SIAM Journal on Computing 26(2), DOI 10.1137/S0097539793260738), and their result holds even when tiles are never stacked more than two deep. In plain words: there is no shortcut that tells you the best move with hidden tiles, which is why the game stays interesting.

In practice, boards are still solved quickly. De Bondt's solver handles "a typical board in less than a second and a worst-case board in about a minute", because it uses safe shortcuts. One of them we use too: when every remaining copy of a tile is free, removing them can never hurt, so the search doesn't branch there.

Where the game came from

The solitaire game is much younger than Mahjong, the four-player tile game. Brodie Lockard wrote a solitaire version called Mah-Jongg on the PLATO computer network after a 1979 accident; he wrote all of its code with a stick held in his mouth, as Brian Dear tells in his history of PLATO, The Friendly Orange Glow (excerpt in Salon). Lockard then designed Shanghai, which Activision released for the Macintosh in 1986 (Computer History Museum catalogue; the Shanghai: Triple-Threat manual credits him as designer). Its turtle layout of 144 tiles is the one most versions still offer, and the one de Bondt measured.

What this means when you play

  1. On our boards, a stuck game is never the deal's fault. There was always a way through, so it's worth asking which earlier pair cost you.
  2. On tall boards, work the high tiles first. On Medium and Hard it was the best of the simple habits we tested; on flat Easy boards it does not help.
  3. Look for crossed piles. If one pile has a dragon over a bamboo and another has a bamboo over a dragon, never match both spare dragons with each other and both spare bamboos with each other: keep at least one spare to release a crossed pile, or the four tiles in those piles lock each other for good.
  4. Shuffle late, not never. A shuffle always gives a clearable position, but each one costs 60 points, so use it when you are truly out of pairs.

Ready to test it? Play Mahjong free on Hard to try the high-tiles habit, where it matters most. For the same question in card games, see how many solitaire deals can be won.

Frequently asked questions

Is every game of Mahjong solitaire winnable?

No. If the tiles are dealt at random, some boards have no solution even for a player who can see every tile. A solver study of 10 million deals of the classic 144-tile turtle layout found 2.95% unwinnable. Some computer versions, ours included, avoid this by building each board so that it can be cleared.

Can every Mahjong board on Extensive Harmony be cleared?

Yes. Our game builds each board by removing random free pairs from a full layout, so playing those pairs in reverse always clears it. The Shuffle button rebuilds the remaining tiles the same way, so a shuffled board can be cleared too. You can still get stuck by taking pairs in a bad order.

Why do I get stuck on a board that can be solved?

Because the order of your pairs matters. In our test, a player who took a random matching pair every turn got stuck on 29.5% of our Easy boards and about 44% of Medium and Hard boards, all of which had a solution. On Hard, taking pairs from the highest layers first got stuck on 37.8% of boards, against 77.2% for lowest tiles first.

Is Mahjong solitaire NP-complete?

Yes, in its perfect-information form: deciding whether a board with every tile visible can be cleared is NP-complete (listed by David Eppstein; Michiel de Bondt published a proof for a restricted case in 2012). With hidden tiles, even approximating the best chance of winning is PSPACE-hard (Condon, Feigenbaum, Lund and Shor, 1997).

Who invented computer Mahjong solitaire?

Brodie Lockard wrote Mah-Jongg on the PLATO system after a 1979 accident, and later designed Shanghai, which Activision released for the Macintosh in 1986. The tile game Mahjong itself is much older and is played by four people.