	X-BASED TRIANGLES
	=================	Triangles X widget, V5.3


    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		SunOS 5.4	X11R5
	PC, 486			Linux 1.0.9	X11R5
	PC, 486			Linux 1.2.8	X11R6(*)

    *	Keypad may not work, since various keycodes may not be defined
	by default.  Check that "KP_1 - KP_9, Home, Up, Prior, Left,
	Begin, Right, End, Down, Next" are defined towards the end of
	/usr/lib/X11/etc/xmodmap.std .  If not defined
	cp /usr/lib/X11/etc/xmodmap.std /usr/lib/X11/xinit/.Xmodmap
	and then motify this or create your own at ${HOME}/.Xmodmap .
	You should just have to uncomment them (get rid of some '!').
	This should be done before X is started.

    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?

    Do you have Motif?  If so, uncomment line 28 of Imakefile.

    It should be easy. Edit the Imakefile (or Makefile.std, see below)
    for appropriate settings of variable SCOREFILE, then do:
	xmkmf
	make
	xtriangles  [motif version will be xmtriangles]

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

    or if you have Motif, uncomment appropriate sections, then try:
        make -f Makefile.std all.xm

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

ANYTHING SPECIAL IN USING?

    Click on the left mouse button to move tile (but not on space or a
      tile that is not in line with space).
    Click on the right mouse button if you want to randomize the puzzle.
      Also 'R' or 'r' do 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 triangles.
    'D' or 'd' to decrease or move down the number of triangles.
    'S' or 's' to auto-solve.  Unfortunately, its unimplemented.
    'U' or 'u' to undo last move.
    'G' or 'g' to get a saved puzzle.
    'W' or 'w' to write or save a puzzle.
    'Q', 'q', or Control-C to kill program.

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

    Tiles can also be moved by the keypad,
    KP_7=>TopLeft		    KP_9=>TopRight
    KP=>Left			      KP_6=>Right
    KP_1=>BottomLeft	  KP_3=>BottomRight

    Notice one can move more than one tile at a time by clicking on the
    tile farthest from the space but in line with the space.

    The title is in the following format (non-motif version):
	xtriangles: <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 Triangles 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
    moves: 0-MAXINT

    startingPosition: array where 0 is the empty space for the UP triangle
      and -1 is the empty space for the DOWN triangle.

    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
 
    Assuming it is a triangle of i triangles in each row and the
    numbering starts from 1.
       Corner 1-> 1
              2-> i^2-2i+2
              3-> i^2

       Center -> i%3 =>
              0: None
              1: j(j+1)+1 where j=2(i-1)/3 
              2: j(j+1)+1 where j=2(i-2)/3+1

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

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

       Same row? -> (m'==n') where s'=sqrt_trunc(s-1) {k}
       Same trbl? -> (((m-1) - m'*m')/2 == ((n-1) - n'*n')/2)) {i}
       Same tlbr? -> (((m'+1)(m'+1) - m)/2 == ((n'+1)(n'+1) - n)/2) {j}
 
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@hertz.njit.edu

HISTORY

  [Apr 08, 96]	V5.3: Minor changes.
  [Jan 31, 96]	V5.2: Tiles will invert, when selected.
		Now using dynamic allocation, so there is no maximum size.
  [Dec 15, 95]	V5.1: Minor updates, RNG for 32/64 bit, border color
		to make faces look more realistic.
  [Oct 01, 95]	V5.0: Xt/Motif, your choice.
  [May 16, 95]	V4.10: Warnings removed from Sun's cc and lint and now
		include a random number generator.
  [Mar 13, 95]	V4.4: Removed lint warnings and added a VMS make.com .
  [Nov 11, 94]	V4.3: Conservative guess for random number generator.
  [Oct 30, 94]	V4.2: Now allows undos, saves, and recalls, also fixed a bug
		where multiple moves were logged for certain single moves.
  [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 06, 92]	V2.0: XView version.
  [Sep 05, 91]	V1.0: SunView version.
