NetLogo banner

 Home
 Download
 Help
 Resources
 Extensions
 FAQ
 References
 Contact Us
 Donate

 Models:
 Library
 Community
 Modeling Commons

 User Manuals:
 Web
 Printable
 Chinese
 Czech
 Japanese

  Donate

NetLogo User Community Models

(back to the NetLogo User Community Models)

TowerofHanoi

by Shayryl Mae Ramos (Submitted: 06/29/2010)

[screen shot]

Download TowerofHanoi
If clicking does not initiate a download, try right clicking or control clicking and choosing "Save" or "Download".

(You can also run this model in your browser, but we don't recommend it; details here.)

WHAT IS IT?

The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of three poles, and a number of disks of different sizes which can slide onto any poles. The puzzle starts with the disks in a stack in ascending order of size on pole A, the smallest at the top, thus making a conical shape.

The objective of the puzzle is to move the entire stack to another pole according to the following rules:

1. Only one disk may be moved at a time.
2. Each move consists of taking the upper disk from one of the poles and sliding it onto another pole, on top of the other disks that may already be present on that pole.
3.No disk may be placed on top of a smaller disk.

HOW IT WORKS

In this program, set of turtles are used to represent a disk which are stored in a list. Once the disk number is called, the assiged set of turtles of that particular disk will be moved from one location to another. And to prevent overlapping of disks, a function will check if there are turtles on the desired region.

HOW TO USE IT

-Select the desired disk design in the drop-down box
-Adjust slider according to the number of disks

-Click START button to load background and poles
-Click GO button to display disks in Pole A
-Click PLAY button to run animation

THINGS TO NOTICE

Notice the turtles in each disks, these turtles will all move to the destination postion. Each of the turtles will move to their assigned locations in A, B and C.

Notice that all turtles in a disk have the same color, this is because color property of the leftmost turtle is copied.

THINGS TO TRY

Try to adjust disk size, the number of steps will also change, thus the amount of time to perform the animation will also increase.

EXTENDING THE MODEL

In the current implementation, all disks will move directly to the destination postion. Try enhancing the animation such that all disks must move up from the current pole, then left (or right) and then move down to the desired location. In this way, it will be more realistic.

NETLOGO FEATURES

Note the use of hatch and the positioning of turtles. These are used to create increasing disks.

CREDITS AND REFERENCES

This model was created by Shayryl Mae Ramos. For concerns, email at shayrylmae@gmail.com

To refer to this model in publications, please use:

Tower of Hanoi. Ramos, S. L. (2010).

(back to the NetLogo User Community Models)