Rally (Marble Puzzle)

[Home]   [Puzzles & Projects]    [Delphi Techniques]   [Math topics]   [Library]   [Utilities]

 

Search

Search WWW

Search DelphiForFun.org

As of October, 2016, Embarcadero is offering a free release of Delphi (Delphi 10.1 Berlin Starter Edition ).     There are a few restrictions, but it is a welcome step toward making more programmers aware of the joys of Delphi.  They do say "Offer may be withdrawn at any time", so don't delay if you want to check it out.  Please use the feedback link to let me know if the link stops working.

 

Support DFF - Shop

 If you shop at Amazon anyway,  consider using this link. We receive a few cents from each purchase.   Thanks.


Support DFF - Donate

 If you benefit from the website,  in terms of knowledge, entertainment value, or something otherwise useful, consider making a donation via PayPal  to help defray the costs.  (No PayPal account necessary to donate via credit card.)  Transaction is secure.

Contact

Feedback:  Send an e-mail with your comments about this program (or anything else).

Search DelphiForFun.org only

 

 

 

Problem Description

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 solution.

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 window size.  

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 

Suggestions for Further Explorations

All of the solutions I have found so far have the yellow marbles displaced from their original locations.  Is it possible to exactly exchange the red and blue marbles leaving the yellow marbles in place?
   December, 2010 - done!: I haven't attempted yet to analyze the game to allow the computer to solve it or give hints.   One of these days........

 

Original Date: January 7, 2003 

Modified: February 18, 2016

 
  [Feedback]   [Newsletters (subscribe/view)] [About me]
Copyright 2000-2017, Gary Darby    All rights reserved.