Tower of Hanoi

1,444
0
Published 2008-09-07
This is a tower of hanoi that knows how to solve itself.

It is part of the 'Taste of ...' series http://chimu.wordpress.com/a-taste-of-scratch



Scratch is an unusual language to program the Tower of Hanoi in because it is missing procedures and recursion. But because of those restrictions, Scratch produces a very interesting and Object-Oriented result. It actually delegates to the Disks better than implementations in other languages like Smalltalk/Squeak or Ruby might choose to do.



Comments are in the Stage and the Sprite1 sprite. If you change Sprite1, simply delete the other sprites, duplicate Sprite1, and set the new Sprite2+ disk-ids appropriately. Sprite1 is the prototype for all the other Sprites (kind of like a 'class' but instance-based. See JavaScript, Self, etc. for examples).