xpuzzles
========

A collection of puzzles.

Web: https://www.sillycycle.com/puzzles.html

Download: Primary site: https://www.sillycycle.com/puzzles
          Secondary site: http://ibiblio.org/pub/Linux/games/strategy

Maintainer: David A. Bagley <bagleyd AT verizon.net>


To configure, build, and install in /usr/local/bin
make -f xpuzzles.Makefile configure
make -f xpuzzles.Makefile         # Motif version built by default
make -f xpuzzles.Makefile run     # this cycles through all
make -f xpuzzles.Makefile install # if you like them
# Any problems please consult the individual README's and let the author know.
# xdial and xthreed are more or less demos and are not built by default.

SLIDING BLOCK PUZZLES
  fixed starting position to set record
xcubes:         expanded 15 puzzle, auto-solves mxnx1 where m & n >= 4
xtriangles:     easier than 15 puzzle
xhexagons:      2 modes: one ridiculously easy, one harder than 15 puzzle
xpanex:         2 modes: hanoi and Panex(tm), auto-solves for all

ROTATIONAL 3D PUZZLES
  hold down control key to move whole puzzle
  letters that represent colors can be changed in mono-mode
  random starting position to set record
xrubik:         a lxmxn Erno Rubik's Cube(tm) (or Magic Cube)
                auto-solves 2x2x2 and 3x3x3 (non-orient mode)
xpyraminx:      a nxnxn Uwe Meffert's Pyraminx(tm) (and Senior Pyraminx),
                a tetrahedron with Period 2, Period 3, and Combined cut modes
                and it also has a sticky mode to simulate a Halpern's
                Tetrahedron or a Pyraminx Tetrahedron
                auto-solves in Period 3 for 2x2x2 and 3x3x3.
xoct:           a nxnxn Uwe Meffert's Magic Octahedron (or Star Puzzler) and
                Trajber's Octahedron with Period 3, Period 4, and Combined
                cut modes and it also includes a sticky mode
xskewb:         a Meffert's Skewb (or Pyraminx Cube), a cube with diagonal
                cuts, each face is cut to have a diamond shape
xdino:          a Triangle - 4 Cube - Dinosaur, (or Triangle - 4 Cube -
                6 Colors) a cube with different diagonal cuts, each face is
                cut to have a "X" shape with Period 3 corner turning, Period 2
                edge turning (Bosch's Cube), and Combined modes
xmball:         a variable cut Masterball(tm), variable number of latitudinal
                and longitudinal cuts on a sphere, where the longitudinal cuts
                permit only 180 degree turns

COMBINATION ROTATIONAL AND SLIDING 3D PUZZLES
  hold down shift key to move whole puzzle
  letters that represent colors can be changed in mono-mode
xbarrel:        a Billion Barrel(tm)
xmlink:         a nxm Erno Rubik's Missing Link(tm), auto-solves 4x4

EXTRA STUFF (just for fun)
xthreed:	a primitive 3D viewer
xdial:		a configurable primitive dial

Other neat X puzzles on the net:
  "puzzle" (X).
  "magiccube" (Motif) - can actually see the cube rotate in 3D space.
  "affenspiel" (X) - a sliding block monkey puzzle at sunsite.unc.edu
    /pub/Linux/games/x11/strategy

Other OS's besides UNIX:
  Runs on VMS with X-Windows and also on MS Windows.
  Java ports of all puzzles available at author's web site.

Some known problems and things to do:
  MinGW versions of rubik and skewb are colored incorrectly.
  cubes: get auto-solve working when sizeX!=1 and sizeY!=1 and sizeZ!=1
  triangles, hexagons: currently have no auto-solve capability.
  triangles, hexagons: double buffering.
  triangles: clean up lines from slide, more scalable using numSlides.
  triangles: variable sides... it would be a hexagon then.
  panex: auto-solve only solves from beginning
  mlink: auto-solve only works when tiles=4 and faces=4
  mlink: initial ordering like cubes?
  barrel: auto-solve for orient mode
  3D puzzles: if colors are made equivalent the program may not
    detect that it is solved.
  rubik: auto-solve only works when size (ie. the number of cubes) on the
    sides are all the same and the size is either 2, 3, or 4.
  rubik: should handle the standard notation for 3x3x3, etc.  This
    notation seems incompatible with the lxmxn cube.  I should also provide
    a hook to do conversions between notations for all puzzles.
  dino: auto-solve only works when it has period 3 movement
  pyraminx, oct, mball: should use more realistic 3D drawing techniques.
  pyraminx: auto-solve only works when the size is 2 or 3 and has period
    movement
  oct: auto-solve only works when the size is 2 or 3 and has period
    4 movement
  mball: auto-solve only works it has wedges <= 8 _or_ 1 band, so
    solves for Saturn Puzzle, Hockey Puck Puzzle, and Masterball.  It would
    be nice to solve for all wedges and bands.

Updates to xpuzzles:
  [Jun 12, 2021]  V8.3.7:
    cubes: Fixed case where puzzle could not be solved or starting position
      was solved already.
    cubes: Small improvement in solver.  Now solves when x=1 or y=1 or z=1.
      Maybe this can be used as a step for a general solution.
  [Jan 21, 2021]  V8.3.3:
    cubes: Autosolve trivial cases.
  [Jan 19, 2021]  V8.3.2:
    rubik: Rubik's Revenge auto-solve for 4x4x4 orient mode.
  [Dec 07, 2020]  V8.3.1:
    Handle corrupted buffer better.
  [Nov 20, 2020]  V8.3.0:
    rubik: Rubik's Revenge (i.e. 4x4x4) solver added.
    rubik, cubes, hexagons: Updated to camel case for sizex to sizeX to be
      consistent with Java version.
    'r' is now for redo and 'g' for get record (formerly read record).
  [Apr 11, 2020]  V8.2.7:
    Fixing a few buffer overflows from latest gcc.
  [Apr 04, 2020]  V8.2.6:
    Lots of spelling errors fixed due to codespell
      https://manpages.debian.org/testing/codespell/codespell.1.en.html
    Updated references to website to https.  https://www.sillycycle.com
  [Feb 15, 2019]  V8.2.1:
    Panex: fixed graphics for Algorithme mode to indicate extra path.
    Fixed spinner to not wrap and be unlimited where appropriate.
  [Oct 02, 2018]  V8.2.0:
    Removing strcpy call by migrating to strncpy.
      Added snprintf compile-time option.
  [Jul 21, 2018]  V8.1.8:
    Fixing sound installation.
    Fixing a check for free from clang for mlink and pyraminx.
  [Apr 03, 2018]  8.1.7:
    Changed slider to spinner a it takes up less room.
    Fixed mball, for odd number of facets, the outermost facet was
      not selectable.
  [Oct 15, 2017]  V8.1.4:
    Removed gcc 7 warnings.
  [Oct 01, 2017]  V8.1.3:
    Updates for 64 bit compilation in Windows.
  [Aug 01, 2017]  V8.1.1:
    Valgrind helped find some definite memory leaks.
  [Jul 17, 2017]  V8.1.0:
    Updated sound configuration for X version.  Uses a simple included
      script play.sh, that is now used by default.
  [Sep 13, 2016]  V8.0.5:
    Old website http://www.tux.org/~bagleyd died, shifted code base to
      new website http://www.sillycycle.com
  [Jan 08, 2016]  V8.0.4:
    Fixed cubes to show only x>=y>=z so there is some uniqueness in puzzle
      complexity and starting position.
  [Feb 24, 2015]  V8.0.0:
    Sound and install fixes.
  [May 19, 2014]  V7.7.5:
    Fix goof in mball.
  [May 13, 2014]  V7.7.4:
    Synchronized save and restore with Java version.
    Fixed synchronizing if resized while reading from saved log for rubik.
  [Jan 20, 2014]  V7.7.3: Not released
    Reorganized pixmap directory.
  [Jan 10, 2013] 7.7.1:
    Cleaned up some duplication in Motif menu.
    Added scroll to feature help dialog.
    New bold fontlist in resource file, so things are easier to read.
  [Aug 31, 2012]  V7.7.0:
    Puzzle control up now makes bigger and down makes smaller
      for cubes, hexagons, mlink.
  [Oct 22, 2010]  V7.6.4:
    Changed key mappings g->r for read file, r->e for redo.
  [Jun 29, 2010]  V7.6.3:
    Added a work around for strange Windows arc behaviour if arcs end at
      0, 90, 180, or 270 degrees in mball.  Work around was to shift by one
      degree.  Not pretty but definitely prettier.
      https://forums.codegear.com/message.jspa?messageID=118084
    Added -perspective to make front most wedges bigger in mball.  Not sure
      I like it general, so made it an option, off by default.  This does
      not change any functionality.
    Added extra keys F12 for CW and F11 for CCW for mball, oct, pyraminx,
      rubik, skewb, dino and F12 for in and F11 for out for cubes.
    Added auto-solve capability for mball with 2, 4, or 6 wedges.
  [Mar 26, 2010]  V7.6.2:
    Auto-solve for oriented mball with only 1 band.  12 wedges simulates a
      Hockey Puck puzzle (solution for 12 wedges taken from
      http://www.jaapsch.net/puzzles/puck.html ).  Wrote a quick program
      to help find moves for a 10 wedge version (included with Java
      distribution as puck.c).
  [Mar 17, 2010]  V7.6.1:
    Added auto-solve capability for mball with 8 wedges.  This includes
      if the wedges are oriented.  If bands are reduced to 1, it can 
      simulate the Saturn Puzzle.
    Changed orientation and terminology from ring to band to be consistent
      with wsd page in for mball.
    Defaults to flip if there if it is ambiguous to turn or flip on a
      "point and click" move in mball, this makes it easier to simulate a
      Saturn puzzle.  Use shift key to do a turn here instead.
  [Jan 21, 2010]  V7.6:
    Version handling changed to a single version.h (and man page).
    Sound fixed for esound.
    Added auto-solve capability for oct (period 4).
  [Jan 13, 2010]  V7.5.6:
    Added auto-solve capability for dino (period 3).
    Orient markers fixed for GL in dino.
  [Jan 07, 2010]  V7.5.5:
    Fixed undo and redo for GL when at fastest speed in rubik, skewb, dino.
    Fixed a way of cheating by switching windows in rubik, skewb, dino.
    Fixed a memory corruption in skewb, dino.
    Added auto-solve capability for skewb.
  [Dec 21, 2009]  V7.5.4:
    Map arrow keys for GL for rubik, skewb, dino.
    Fix goof for twisting in OpenGL for skewb.
  [Dec 11, 2009]  V7.5.3:
    Added more delay for GL in rubik, skewb, dino.
    Added variable speed from rubik for randomizer and undo/redo in
      skewb, dino.
    Fixed flash in control draw in skewb, dino.
    Can now see actual twisting in OpenGL in dino.
  [Dec 07, 2009]  V7.5.2:
    Can now see actual twisting in OpenGL in skewb.
  [Nov 10, 2009]  V7.5.1:
    Windows version: added accelerator for references.
    GLU used for GL mouse mapping for rubik, skewb, dino.
      Gutted old 3d representation (except when no OpenGL available).
    Windows fix: changed GL code until no drawing errors, some Windows
      machines needed this for rubik, skewb, dino.
  [Jun 05, 2009]  V7.5:
    Fixed view for Windows not to reset puzzle for rubik, skewb, dino.
    Cleaned up menu look.
    Fixed for NAS sound.
  [Dec 21, 2008]  V7.4.3:
    Fixed for NAS sound.
  [Nov 15, 2008]  V7.4.2:
    panex: new Algorithme mode.  Auto-solve for this now solves in
      minimum number of moves.  Also need to steal jump move (a move from
      stack 1 to stack 3) from cubes puzzle.
  [Jul 21, 2008]  V7.4.1:
    Strange character at end of help title removed.
    pyraminx: Fixed a possible timing auto-solve problem.
  [Jul 11, 2008]  V7.4:
    Leading function names in lowercase.
    panex: Fixed background color problem.
    pyraminx: Fixed turning bug when selecting face 2 then face 1
      when horizontal.
    rubik, skewb, dino: Extra callback was causing 2d to go out of sync.
    rubik: Mouse release sometimes was using wrong face.
  [Feb 29, 2008]  V7.3.4: Not released
    Changed pointer from crosshair to hand2.
  [Dec 24, 2007]  V7.3.3:
    Constants changed.
    Windows error fix for cubes, hexagons, mlink, rubik when changing size.
    Added 3D look to frame for cubes, triangles, hexagons, panex.
    rubik bug found when changing size while GL puzzle rotating.
    rubik randomizes to a maximum of 100 moves.
  [Nov 06, 2007]  V7.3.2:
    Fixed drawing errors on mlink and barrel rotation.
    barrel: 1B had and extra move in solution.
    Updated action codes and synchronized Java and C code.
    Various small changes.
  [Apr 10, 2007]  V7.3.1:
    Sound added for mball, pyraminx, oct, dino, skewb, rubik.
    barrel: Auto-solve.
    barrel: Fixes for get and write.
    mlink: Fix for get.
  [Feb 23, 2007]  V7.3:
    Html no longer corrupted.
    reverseVideo update.
  [Jan 08, 2007]  V7.2.7:
    New bump.au sound, db lowered, and bumpdat.au removed, thanks to
      http://audacity.sourceforge.net to help clean the sound up.
  [Dec 12, 2006]  V7.2.6:
    Changed default so that practice is true for puzzles that have it:
      xrubik, xskewb, xdino, xpyraminx, xoct, xmball, xmlink, xbarrel.
    Now use http://netpbm.sourceforge.net to generate images from xpm.
  [Nov 09, 2006]  V7.2.5:
    xdino: Fix some orient line OpenGL problems.
    xdino: Fix Period 2 OpenGL problems.
    wrubik, wskewb, wdino: Windows OpenGL stuff now ported.
    wcubes, wmlink, wpanex, wpyraminx, wrubik: Windows version
      interruptible on auto-solve.
    xpyraminx, xoct: Drag and drop between adjacent faces.
    xpyraminx: Fixed minor drawing errors for orient lines.
    xpyraminx: Fixed bug when changing to Period 2.
  [Oct 11, 2006]  V7.2.4:
    xrubik, xskewb, xdino: drag and drop between adjacent faces.
    xdino: OpenGL for xdino added.
    xskewb, xdino: Orienting faces for OpenGL added.
    skewb: Control-Alt was not working right for OpenGL.
    xrubik, xskewb, xdino: added view option for OpenGL, "v".
    Fixed menu to assure the ok part of queries is handled correctly.
      (Bug fixed from redo change in xpanex, xmlink, xbarrel, xmball,
      xpyraminx, xoct, xrubik, xskewb, xdino).
  [Aug 22, 2006]  V7.2.3:
    cubes: Should now always work for all arrangements.  For example, 3x3x3
      was wrong.
  [Jul 21, 2006]  V7.2.2:
    Fixed assorted memory leaks and uninitialized memory access reads.
    r is now for redo.  z is now the character for randomize.
    triangles: no more fully random positions, a starting position is
      made by randomly turning puzzle CCW or CW (+-120 degrees).
    hexagons (corners): shifting them down by 2's work.
      x=1 and y=n top and bottom pieces are always trapped.
      There are some positions that are weird...  x=1 y=3 and x=2 y=2 in
      particular and  and these cases have to have special handling.
      x=1 y=3     x=2 y=2   special starting positions
         X          X X
        X 1        4 3 1
       5 4 2        5 2
        6 3
         7
    hexagons (no corners): shifted by 1, actually always solvable from
      EVERY position, except x=n y=1 this case is easily handled.
    cubes: Starting position instead of random
      Tried shifting by one and all reversed but made solutions too trivial.
      Starting pattern is ordered going down columns.
        1  4  7 10        1  2  3  4
        2  5  8 11   =>   5  6  7  8
        3  6  9  X        9 10 11  X
      Special case of 2x2x1 is handled (or else its solved already).
      Nx1x1 to be handled also.
      Some patterns require the last numbers to be swapped in order for the
      puzzle to be solvable.
      Does it always work for all arrangements... not sure...
  [Jun 10, 2006]  V7.2.1:
    xrubik, xskewb, xdino: get fix for Windows.
    xrubik: undo needed debouncing on own window.
    Recognize solved when doing undo where practice option exists.
    xpanex: scan instant and undo at double speed.
    xpanex: fixed drawing errors.
  [Apr 01, 2006]  V7.2:
    Made usage string compatible with versions of Motif and screen.
    More defensive code in case getlogin fails.
    xpanex: in hanoi mode illegal moves are handled better.
    xmlink: solve fix for swapping left most middle tiles.
  [Oct 05, 2005]  V7.1.5:
    scoreFile and userName fixes
    -version added
    -score added
    Common option help for X and X-Motif
    xhexagons: made corners key "o" to be consistent with alhextris
  [May 31, 2005]  V7.1.4:
    Separated out compatible components (this was done to clean things
      up so code can be reused for altris games (tetris, welltris,
      hextris, & tertris)).
  [Feb 8, 2005]  V7.1.3:
    xmlink, xbarrel, xcubes, xhexagons, xmball, xpyraminx, xoct, xrubik,
      xskewb, xdino, xthreed... mouse wheel for Windows now works.
    xmlink, xbarrel, xpanex
      Rotating tiles and panex now mouse motion sensitive.
      Small graphical fixes.
    xthreed a 3d viewer made slightly less primitive.
      Mouse can now find a face of polyhedron.
  [Dec 12, 2004]  V7.1.2:
    Thanks to Debian maintainer Florian Ernst <florian AT uni-hd.de> for
      esound fix and non-motif xrubik fix.
    xpanex:
      Speed implemented better and sound added.
      Fixed bug where changing complexity does not clear cheat flag.
      Did not easily start over if solved.
      Animation.
    xmball man page cleanups.
    Took out "2" for toggle of sound, only "@" from keyboard.
      This is to synchronize with Java code.
  [Sep 29, 2004]  V7.1.1:
    xhexagons animation.
    xtriangles and xhexagons: Sound, "<" and ">" speed control.
    xmlink and xbarrel: Better speed control with "<" and ">".
    xcubes, xmlink, xbarrel:
      Installation of sound and mandrill files.
  [Aug 23, 2004]  V7.1:
    Thanks to Debian maintainer Florian Ernst <florian AT uni-hd.de> for
      fixing a compilation problem with X and without Motif.
    Added font option.
    xcubes, xmlink, xbarrel:
      Better double buffering.
      Picture option added, many ideas including the mandrill were
        borrowed from X puzzle by Don Bennett, HP Labs.
      Sound added.
      Sort of real time using gettimeofday.
  [Aug 10, 2004]  V7.0.2:
    Menus and help for xthreed.
    xoct: Thanks to Debian maintainer Florian Ernst <florian AT uni-hd.de>
      for fixing a compilation problem with X and without Motif.
  [Dec 15, 2003]  V7.0.1:
    Undo fix and CW/CCW swap for xskewb.
    Mono fix for barrel.
    Colors on dino corrected.
    The Hide functionality of the Escape key now iconifies or drops in
      task bar.
    Accelerator Keys (F keys and regular keys) in Windows now work.
    Added help in Windows.
    Integrated Windows source into xpyraminx, xoct, xrubik, xskewb, xdino.
    wmlink & wbarrel: Animate rotate ported to Windows.
    wcubes: Auto-solve now works.
    wmball: Now avoids using FloodFill in Windows.
  [Nov 15, 2003]  V7.0:
    xbarrel: New puzzle.
    xthreed: color pixmap added.
    xhexagons, xmlink: Fixed message initialization, it got truncated due
      to switch initialization.
    xmlink: added a practice mode.
    Started integration of winpuz6.5 (Windows 3.1/95) into X source tree.
  Some older versions used Windows (6.x), Xt/Motif (5.x), Xt (4.x),
    Motif (3.x), XView (2.x), and SunView (1.x), see individual README
    files of each package for a more complete listing.

xpanex, xpyraminx, and xoct are my favorites.  Questions about the above,
  feel free to ask me...


STARTING POSITION
 Instead of a random starting position make a starting position.
    Here records will make more sense because it does not involve a lucky
    random position.  May still want to have a randomize....
    Ideas follow... not mathematically proven.  :)

    Hexagons (corners): shifting them down by 2's work.  see
    https://www.sillycycle.com/hexagons.txt   Does it always work for normal
    arrangements... not sure...
    There are some positions that are weird...  x=1 y=n, x=2 y=2 and these
    cases have to have special handling.

    Hexagons (no corners): always solvable from EVERY position,
    except x=n y=1 this case is easily handled.

    Cubes:
      For example:
          1  2  3
       4  5  6  7
       8  9  10 11
       12 13 15 14
            ||
            \/
       1  2  3  4
       5  6  7  8
       9  10 11 12
       13 14 15

    Note for a 1x4 puzzle this will not work.  :)  Just shifting them all
    down by 1 would.

    How everything is still handled ... not sure.
    [] 1  2  3  4   | 15  16  17  18  19
    5  6  7  8  9   | 20  21  22  23  24
    10 11 12 13 14  | 25  26  27  28  29

    another possible arrangement (that may work better?)
    1  4  7 10        1  2  3  4
    2  5  8 11   => 5  6  7  8
    3  6  9           9 10 11

    If that does not work swapping the last numbers 10 and 11 will.
    (Another arrangement: a combination of the two ideas)

    If you want to pursue this I would like to make sure that the puzzle
    is always solvable first and have a rule for the exceptions, notably
    permutations of 2x2x1 and nx1x1.

    Considering a mxnx1...  this seems to be true:
      If m and n are both even then need to switch the last two numbers
      Else you don't
    I would suspect its something like for lxmxn
    all odd ok
    1 even ok
    2 even  needs a swap
    3 even ok

    triangles:
    A starting position can be made if you turn it CCW (or CW) 120 degrees
    This works because the puzzle is symmetrical.  It would not work for
    hexagons and cubes since the puzzle is not always symmetrical and in
    the case of cubes...  planar.
    Size = 3
        ^
        v
      4   7
      3   6
    1   2   5
       ||
       \/
        1
        3
      2   4
      6   v
    5   7   ^
    The puzzle is ALWAYS solvable from a rotated position
