# Mahjong solitaire

Mahjong solitaire (also known as Shanghai solitaire, electronic or computerized mahjong, solitaire mahjong or simply mahjong) is a single-player matching game that uses a set of mahjong tiles rather than cards. It is more commonly played on a computer than as a tabletop game, although it can be played using physical tiles using a special wooden frame for its lengthy set-up process.
Although named after the four-player tile game mahjong, the method of gameplay is unrelated.

## Play

The 144 tiles are arranged in a four-layer pattern with their faces upwards. A tile is said to be open or exposed if it can be moved either left or right without disturbing other tiles. The goal is to match open pairs of identical tiles and remove them from the board, exposing the tiles under them for play. The game is won when all pairs of tiles have been removed from the board, and lost if the remaining tiles contain no exposed pairs.

### Mathematical analysis

Playing Mahjong solitaire optimally in the sense to maximize the probability of removing all tiles is PSPACE-complete, and the game is NP-complete if looking below tiles is allowed. It has been proven that it is PSPACE-hard to approximate the maximum probability of removing all tiles within a factor of $n^{\epsilon }$, assuming that there are arbitrarily many quadruples of matching tiles and that the hidden tiles are uniformly distributed. The perfect-information version of this puzzle is where the player knows, before the game starts, the position of every tile. In this case, however, it is NP-complete to decide whether all tiles can be removed.
An analysis of ten million games with the default layout, "the turtle", found that about 3 percent of the turtles cannot be solved even when looking below tiles is allowed.

## Computer game history

The computer game was originally created by Brodie Lockard in 1981 on the PLATO system and named Mah-Jongg after the game that uses the same tiles for play. Lockard claimed that it was based on a centuries-old Chinese game called "the Turtle". The computer game was released for free and was played using a CDC-721 touch screen terminal.
Activision released Shanghai in 1986 for the IBM Personal Computer, Commodore Amiga, Macintosh, Atari ST and Apple IIgs. The Macintosh version was created by Brodie Lockard, and the Apple IIGS version was ported from the Macintosh by Ivan Manley with Brad Fregger as the producer. Around 10 million copies were sold. The game has since been ported to many different platforms. The name "Shanghai" was trademarked by Activision.
As the game is based on mahjong tiles, some confusion arose with the 4-player mahjong game. Although the name mahjong solitaire is widely used, other names include The Turtle, Shanghai Solitaire, Taipei, and Kyodai.
A version of this game was also included in the Microsoft Entertainment Pack for Windows 3.x in 1990 under the name Taipei. It was subsequently included in the Best of Windows Entertainment Pack. Premium editions of the Windows Vista operating system and Windows 7 include a version of the game known as Mahjong Titans.
Mahjong solitaire was adapted into several puzzle video games such as Mahjong Trails, listed as one of the top-grossing games on Facebook.
Mahjong Solitaire was added to Clubhouse Games: 51 Worldwide Classics for Nintendo Switch. It includes a two-player version.

## Variations

Mahjong solitaire is usually played in an electronic form as a computer game. Some electronic Mahjong solitaire games offer extra options, such as:
* Shuffling the tiles;
* Changing the tile set and patterns from the traditional tiles to flowers, jewels or other items that may be easier to match up at a glance;
* Playing a series of different layouts with varying levels of difficulty (usually given Chinese-looking names such as 'the ox' or 'the snake');
* Adding "wildcard tiles" and other tiles that have special functions.
* Adding more pairs, so larger layouts can be made. Sometimes they are new symbols, and sometimes they are extras of normal ones.
* Adding a time limit based on the number of tiles in the initial layout.
Mahjong solitaire can be played either solo or with a partner, in which case the aim is to accumulate the most pairs, to be the last one to match a pair, or to score the most points. Points are gained for each pair removed, with bonus points for removing matched pairs in sequence or removing pairs in sequence that are parts of sets. Using traditional mahjong tiles, the sets include the dragons, the flowers, the seasons, and the winds.
Some implementations offer to shuffle the tiles when there are no exposed pairs remaining, making it almost always possible for the player to complete the game. Many implementations offer undo, and nearly all versions will not generate a board that can't be won even with undo.