Last night I wrote an RB program to calculate the moves needed for the Tower of Hanoi, the object of which is to transfer all of the disks of different sizes on one peg or pole to another. (There are three pegs, two of which start out empty.)
There are essentially only two rules: (1) you can move only one disk at at time. (2) No disk may be placed on top of a smaller disk.
Important: I did not write the game program itself. (I'm hoping to find someone here who may be interested enough to work with me on that.) What I wrote was a program which shows the minimum moves, step-by-step, required to solve the puzzle.
Here's where you can find the source code for my program:
http://traver.org/RB2013/Hanoi.rbpHere's the Web page that inspired me:
http://britton.disted.camosun.bc.ca/jbhanoi.htmAnd here's a sample of what my program does:
_____
SOLUTION FOR 10 DISKS
(1023 moves minimum required)
1 (Move 1): Move disk 1 onto empty peg.
10 (Move 2): Move disk 2 onto empty peg.
11 (Move 3): Move disk 1 onto disk 2.
100 (Move 4): Move disk 3 onto empty peg.
101 (Move 5): Move disk 1 but NOT onto disk 3.
....
_____
My program was written in Windows, which uses Chr (13) as an end-of-line marker for text inside a TextArea. That will have to be changed for the program to work properly on the Mac or on Linux.
What I'm looking for from people on the Forum is suggestions for improvement of my program. (If someone wants to write, say, something that will allow people to play the game on their own computer, that would be great!) If you prefer to send me a private email rather than posting a note, that would be okay, but posting on the Forum would enable others here to benefit from the discussion. My objective here is to encourage sharing of code.
Barry Traver
P.S. I'm actually hoping that I may find here at least a few hobbyist programmers who have an interest in working together on logic-type games, such as those discussed by Martin Gardner in his "Mathematical Games" column in Scientific American in years past.