	X-BASED HEXAGONS
	================	Hexagons X widget, V4.10


    It has been tested on the following platforms:

	HP 3xx & 700		HP-UX 9.0x	X11R5
	Sun4, SPARC		SunOS 4.1.3	X11R4
	Sun4, SPARC		Solaris 2.3	X11R5
	PC, 486			Linux 1.0.9	X11R5

    If yours is not in this list, please let me know -- thanks. The
    most updated source could be found on ftp.x.org under
    /contrib/games/puzzles.

HOW TO BUILD?

    It should be easy. Edit the Imakefile (or Makefile.std, see below)
    for appropriate settings of variable SCOREFILE, RANDOM, then do:
	xmkmf
	make
	xhexagons

    If that does not work then:
	mv Imakefile Imakefile.r5
	sed 's/^XCOMM/\/\*\*\/#/' > Imakefile < Imakefile.r5
	xmkmf
	make
	xhexagons

    Note: if you don't have 'xmkmf' or the "Makefile" it generates
    doesn't work well, edit Makefile.std for appropriate settings for
    XINCLUDEPATH and XLIBPATH, then try:
	make -f Makefile.std

    You should have Hexagons.ad copied to $(HOME)/Hexagons or 
    /usr/lib/X11/app-defaults/Hexagons to run, especially if the background
    is similar to one of the faces. Edit this file for your preferences.
    You might want to move xhexagons into /usr/bin/X11 (or wherever your
    X binaries are).
    You might also want to move xhexagons.man to /usr/man/man6/xhexagons.6

ANYTHING SPECIAL IN USING?

    Click on the left mouse button to move tile (but not on a space or
      not in a line with a space, if there are 2 spaces it will move a
      free tile to a numerically higher position).
    Click on the middle mouse button to move tile (but not on a space or
      not in a line with a space, if there are 2 spaces it will move a
      free tile to a numerically lower position).
    Click on the right mouse button if you want to randomize Hexagons.
      Also 'R' or 'r' does the same thing.  One must double click on
      the right mouse button if the puzzle is being worked on.
    'I' or 'i' to increase or move up the number of hexagons.
    'D' or 'd' to decrease or move down the number of hexagons.
    'C' or 'c' to toggle corners mode.
    'S' or 's' to auto-solve.  Unfortunately, its unimplemented.
    'U' or 'u' to undo last move.
    'E' or 'e' to enter saved puzzle.
    'W' or 'w' to write or save a puzzle.
    'Q', 'q', or Control-C to kill program.

    Key pad is defined for Hexagons as:
    7       9
        ^
    4 <   > 6
        v
    1       3 

    Tiles can also be moved by the keypad,
    KP_7=>TOP LEFT (TL)		KP_9=>TOP RIGHT (TR)
    KP=>LEFT			KP_6=>RIGHT
    KP_1=>BOTTOM LEFT (BL)	KP_3=>BOTTOM RIGHT (BR)

    In corners mode, one can only move one tile at a time. The only
    tiles that can be moved are the tile(s) next to both spaces. In the
    other mode, one can move more than one tile at a time and one is
    not constrained by parity.

    The title is in the following format:
	xhexagons: <size> @ (<Number of moves>/\
		{<Record number of moves>|NEVER|PRACTICE}) - <Comment>
    {<Record...}: puzzle is either in practice mode or record mode
       In record mode, if there is no record of the current puzzle, it
       displays "NEVER".

    If you were looking for a auto-solver, sorry.

    Keep in mind that Hexagons is a widget that can be simply stuck in
    other X programs. (If you find a use for this, let me know).

    Refer to the man page for detailed command line options.

    If you want further information on puzzles, I'll be glad :-) to send
    it to you.

SAVE FORMAT

    The format is not standard.  The reason is that this is simple to
    produce and I do not know what the standard is.  The format will
    probably change to become more readable.

    size: number of tiles in a row
    corners: 0 false, 1 true  hexagon corners
    moves: 0-MAXINT

    starting position: array where 0 is the empty space for the HIGH hexagon
      and -1 is the empty space for the LOW hexagon.

    This is then followed by the moves
    move #: direction
    Direction is represented as 0 upper right, 1 right, 2 lower right,
      3 lower left, 4 left, and 5 upper left.

    Caution: the program may crash on corrupted input.

MATHEMATICAL BASIS
 
    Lets start out with a triangle of hexagons for simplicity's sake
    and then expand these ideas to a hexagon of hexagons

    Assuming it is a triangle of i hexagons in each row and the
    numbering starts from 1.
       Corner 1-> 1
              2-> i(i+1)/2 - i + 1
              3-> i(i+1)/2

       Center ->i%3 =>
              1: (2i'-1)*(2i')/2-i'+1 where i'= (i+2)/3
              default: None

       Max_Width -> i * 3^(1/2) units
       Max_Height -> (3/2)i+(1/2) units

       Start -> x= i * 3^(1/2)/2 units
                y=0
                fin=i
                step=i
       Next -> (n==fin) =>
               true: x+= -3^(1/2) * (2 * step - 1)/2 units; y+=3/2 units;
                     step++; fin+=step
               default: x+= 3^(1/2) units

       Same row? -> (m'==n') where s'=(1+sqrt_trunc(1+8*(s - 1)))/2 {k}
                                i.e. s = s'(s'-1)/2
       Same trbl? -> (m-1)-m'(m'-1)/2 == (n-1)-n'(n'-1)/2 {i}
       Same tlbr? -> (m'+1)m'/2-m == (n'+1)n'/2-n {j}

    Now assuming it is a hexagon of i hexagons in each row and
    the numbering starts from 1.
       Corner 1-> 1
              2-> i
              3-> Center - i + 1
              4-> Center + i - 1
              5-> 3i(i-1) - i + 2
              6-> 3i(i-1) + 1

       Center -> 3i(i-1)/2 + 1

       Max_Width -> (2i-1) * 3^(1/2) units
       Max_Height -> 3i-1 units

       Start -> x= i * 3^(1/2)/2 units
                y=0
                fin=i
                step=i
       Next -> (n<=center) =>
            true: (n==fin)
              true: x+= -3^(1/2) * (2 * step - 1)/2 units; y+=3/2 units;
                    step++; fin+=step
              default: x+= 3^(1/2) units
            default: (n==fin)
              true: step--; x+= -3^(1/2) * (2 * step - 1)/2 units;
                    y+=3/2 units; fin+=step
              default: x+= 3^(1/2) units

       Same row? -> (m'==n') {k} where (s<=center) =>
            true: s' = (1+sqrt_trunc(1+8*(s+i*(i-1)/2)))/2-i
                           i.e. s = s'*(2s'-1)-(i)(i-1)/2
            default: s' = 3*i-2-(1+sqrt_trunc(1+8*(3i(i-1)+1+i*(i-1)/2-s)))/2)
       Same trbl? -> (m''==n'') {i} where (s<=center) =>
            true: s'' = (s+i*(i-1)/2)-(s'+i)*(s'+i-1)/2
            default: s'' = 2*i-2-(3i(i-1)+i*(i-1)/2-s-(3*i-s'-2)*(3*i-s'-3)/2)
       Same tlbr? -> (m''==n'') {j} where (s<=center) =>
            true: s'' = -1-((s+i*(i-1)/2)-(s'+i+1)*(s'+i)/2)
            default: s'' = 2*i-1+(3i(i-1)+i*(i-1)/2-s-(3*i-s'-1)*(3*i-s'-2)/2)
 
FOUND A BUG?

    Send bugs reports and fixes to the author. For bugs, please include
    as much information as to their location as possible, since I may not
    have the resources to duplicate the them.

	David Albert Bagley,	bagleyd@source.asset.com

HISTORY

   [May 16, 95] V4.10: Warnings removed from Sun's cc and lint and now
		include a random number generator.
   [Mar 13, 95] V4.5: Removed lint warnings and added a VMS make.com .
   [Nov 11, 94] V4.4: Conservative guess for random number generator.
   [Nov 02, 94] V4.3: Now allows undos, saves, and recalls.
   [Aug 23, 94]	V4.2: Switched left and middle buttons on the mouse to
		have up and down consistent with vi's "j", "k" keys.
   [Jun 28, 94]	V4.1: Can accommodate a auto-solver.
   [Jun 07, 94]	V4.0: Xt version.
		I got some good ideas from oclock.
   [Apr 01, 93]	V3.0: Motif version.
		I got some good ideas from Douglas A. Young's
		book: "The X Window System Programming and Applications
		with Xt OSF/Motif Edition", particularly his dial widget.
		I got some good ideas on presentation from Q. Zhao's
		tetris.
   [Jan 07, 92]	V2.0: XView version.
   [Sep 06, 91]	V1.0: SunView version.
