Rally is a puzzle with 32 marbles colored as
shown and free to rotate in the horizontal or vertical oval
tracks. The objective is to rearrange the marbles by rotating them so that the 12 red
marbles in the center square are replaced by blue marbles.
Background & Techniques
This puzzle is from a fun book, "1000 PlayThinks",
written by Ivan Moscovich and published by Workman Publications. I
hope they don't mind my implementing this one in Delphi. A
move is defined as rotating marbles in the vertical or horizontal tracks
in either direction by as many positions as desired.
Moscovich's solution takes 10 moves, but that is far from optimum. I
found a solution on the web that solves the puzzle in 3 moves!
I'm not publishing it here because you might want the fun of discovering
it for yourself. If not, you might want the fun of searching the web
to find the solution or sending me a feedback email requesting the
Non-programmers are welcome to read on, but may
want to skip to the bottom of this page to
download executable version of the program.
The program has about 400 lines of user
written code - but half of that is in the Redraw procedure which
draws the track and sets marble positions based on the current screen
size. Track and marbles are dynamically resized based on
A TSlots record defines a marble slot including
its current color, and rectangles defining its base location and
intermediate positions 1/3 and 2/3 of the way to the next slot in a
clockwise direction. These intermediate positions are used to
animate marble moves. HSlots and VSlots are arrays each
containing 18 TSlot records representing the 18 marbles in
horizontal and vertical tracks.. Four marble positions
overlap between the two tracks and when one track is rotated then common
positions in the other track must be updated. Procedure SynchForm
accomplishes this after each move.
Addendum December 2, 2010: Version
2 of the puzzle was posted today to correct some display problems
encountered on my high resolution laptop screen (1960x1280 DPI, which
turned out to be a pain in the you-know-what. These old eyes need
to use DPI
scaling to make things readable which in turn requires some special
programming considerations). Since I couldn't locate the
solutions referenced above, and to see if I still had it, I also
implemented a depth-first search for solutions . I just did the
fun part, finding the solutions, but left animating the solutions up to
the user. Just enter the moves listed to verify that they work.
Running/Exploring the Program