Mahjong solitaire is a matching game: you take pairs of identical tiles off a 144-tile pile, but only tiles that are free — nothing stacked on top, and at least one long side open.
The obvious way to deal a board is to shuffle 144 tiles and drop them onto the layout. It is also wrong. A random arrangement can easily be unwinnable — the last four tiles buried under each other, two of a pair locked in positions that can never both be free. You do not find out at the start. You find out twenty minutes in, when nothing matches and there is no way back.
Try a few free mahjong sites and you will hit it. It is not a rare edge case; forward dealing produces unwinnable boards routinely.
Deal the board by playing it backwards
The fix is to stop generating boards and then checking them, and instead generate a solution and derive the board from it.






