About Me | Site Map | Contact Me

Tower of Hanoi

Introduction

There are 3 towers, with some disks on the left tower but nothing on the middle and the right towers. Try to move all disks on the left tower to the right tower. The constraints are:

  • Each time you can move 1 disk - the topmost one on any tower.
  • At any time only smaller disks can be put on top of larger disks.

It's not only fun but also helps you understand how recursive algorithm works.

Visualization

Below is my java applet implementation. It consists of 3 windows:

  • The upper left window shows the movement of disks on the three tower.
  • The lower left window shows the algorithm with highlight on current executing code.
  • The right window shows stack content.

My applet operates in two modes:

  • Automatic Mode - Algorithm Visualization
  1. Click the "Auto Solve" radio button at the upper-right corner, choose number of disks using the combo-box at the upper-left corner, and then press the "Start" button at the lower-left corner.
  2. Algorithm can be executed automatically or one step at a time.
  3. The panel on the right shows changes in the run-time stack.
  • Manual Mode - To Play the Game and Move the Disks Yourself.
  1. Click the "Get My Hands Dirty" radio button at the upper-right corner, choose number of disks desired using the combo-box at the upper-left corner, and then start to move the disks.
  2. Only the top-most disk can be moved at any time. To move a disk, simply move your mouse over the disk, click, and drag the disk to the desired post while holding down the mouse button.
  3. A timer will start when you make the first move.
  4. You may find the stack on the right side of the applet useful. If you press the "Choices" button, it can generate all possible movements from the current state of the three towers.

Client Requirements

Theorectically any browser supporting Java runtime 1.3 or later.

Oops...

The embedded application cannot start. Please check the client requirements section above. Below is a screenshot showing what the application looks like when running.

If you are using Netscape/Mozilla/Firefox, please try this link.


Last Updated: March 1, 2006
(Cedric) Qin Zhang CSDL, ICS, UHM