                           MAH JONGG SOLITAIRE

                             by Loren Blaney


This game allegedly was invented by the Chinese about 3000 years ago. The
idea is to remove all the tiles from the pile, which is called a
"dragon". Tiles are removed in matching pairs by using the mouse to click
on them.

The tiles must be removed from the left or right sides of each layer.
Tiles in the middle are blocked and cannot be removed until the outer
tiles have been cleared away.

There are 144 tiles consisting of 36 groups of four matching tiles. Most
groups have four identical tiles, but two of the groups, the seasons and
flowers, have different although related images. For instance, summer
matches autumn.


CONTROLS

Information about the game is displayed in the upper-right corner.

    Tiles - Shows the number of tiles remaining in the dragon (0-144).

    Time  - Shows the time elapsed since starting the game (min:sec).

    Game  - Shows which tile formation is being played (0-999).


The highlighted rectangles are buttons.

    Hint - Shows a pair of unblocked matching tiles. If pressed
           repeatedly, all such matching tiles are shown.

    Undo - Takes back the previous move.

    Redo - Redoes moves taken back with the Undo button.

    Used - Displays tiles that have been removed from the pile.

    New  - Starts a new game. Press it a second time to verify.

    Exit - Exits the program. Press it a second time to verify.


When the Used button is pressed, these buttons are displayed.

    Sort - Alternately displays tiles in numeric order or in the
           order they were removed.

    Play - Returns to the main screen to resume game play.


Normally the game number is selected at random, but you can select a
particular game by clicking on the game number and typing in a new value
(0-999). Hit Enter to begin, or Esc to return to the current game.



STRATEGY

All of the tiles must be removed to win. Initially it's easy to remove
pairs, but later in the game, the pairs will often be blocked. Because
there are six different ways that four matching tiles can be removed,
there are many possible moves, and consequently, many ways to lose the
game. Whenever you can remove all four matching tiles at once, you
should, because this avoids the dilemma of which is the correct order to
remove them.

Try to remove tiles that block the most other tiles as soon as possible.
For example, in the initial formation the tile on top blocks the four
tiles immediately under it, and therefore it should be removed soon.

Look for matching pairs of tiles near each other in the same row. These
tiles are a problem because if you remove the other matching pair then
this row must be cleared from both ends before this second pair of tiles
can be removed.

Since the dragon is built from randomly selected tiles, some of the
formations (games) cannot be solved. For instance, it would be impossible
to solve a game with three matching tiles stacked on top of each other.

Many people just like to try to solve the games that are selected at
random. Others like to systematically go through the games working on
each until they either solve it or prove that it is impossible. I know
for a fact that games 1 through 5 are solvable, and 6 is easy.



XPL0 PROGRAMMING LANGUAGE

If you're wondering about the language used to program Mah Jongg, it's
called XPL0. You can probably get the compiler and related tools from the
same place that you got this file. Look for XPL0-30.ZIP. XPL0 was
created by a computer club called The 6502 Group at the Colorado School
of Mines during the mid 70s. Although very few people know and use XPL0,
it competes surprising well with popular languages such as C, Pascal, and
BASIC.

XPL0 features fast, optimized compiles, block structure, recursion,
16-bit integers and 80-bit floating point; it supports math coprocessors,
hexadecimal and ASCII constants, boolean and shift operators, large code
and data space (> 64K), arrays with any number of dimensions; it has
generalized device I/O for console, printer, files, comm ports, etc,
include files, separately compiled modules, external assembly-language
routines, built-in graphic routines with high-speed line draw, built-in
trig and log functions, peek and poke, port I/O, extensive compile and
run-time error checking, cross-reference generator; it comes with a
129-page manual with index and many program examples, such as this one.

There are several implementations of XPL0 that run on PCs. One compiles
fast native 8088 assembly code, while another generates compact
interpreted code that doesn't require an assembler. There is 32-bit
version for 386+ processors that addresses 4 gigabytes of memory.

Here is an example of a simple XPL0 program:


\SIEVE.XPL      SEP-28-97
\Eratosthenes Sieve Prime Number Program

code    Crlf=9, Intout=11, Text=12;
define  Size = 8190;
integer Prime, Count, Iter, I, K;
char    Flags(Size+1);

begin
Text(0, "10 iterations
");
for Iter:= 1, 10 do                             \Do program 10 times
        begin
        Count:= 0;                              \Prime counter
        for I:= 0, Size do
                Flags(I):= true;                \Set flags all true
        for I:= 0, Size do
            if Flags(I) then                    \Found a prime
                begin
                Prime:= I +I +3;                \Twice the index + 3
                K:= I + Prime;                  \First multiple to kill
                while K <= Size do
                        [Flags(K):= false;      \Zero a non-prime
                        K:= K +Prime];          \Next multiple
                Count:= Count +1;               \Primes found
                end;
        end;
Intout(0, Count);   Text(0, " primes
");                                             \Primes found in 10th pass
end;



Thanks for your interest in Mah Jongg and XPL0.

loren.blaney@gmail.com
