CPSC 170 Spring 2005
Program 2: Towers of Hanoi
Due Friday, March 4, 2005

Description

As we discussed in class, Towers of Hanoi is a game with 3 "needles" (pegs) and N graduated disks. Initially the disks are all on the first needle, with the largest on the bottom and the smallest on the top. The object of the game is to move all of the disks to the second needle while abiding by the following rules: We discussed an elegant recursive solution to this problem, and that it takes 2N-1 moves to transfer N disks from the first needle to the second following these rules.

Your assignment is to write an interactive program that graphically demonstrates the Towers of Hanoi game for a variable number of disks. Your program should have the following behavior:

Note that the user does not get to choose what moves are made; the clicks just prompt the next move toward the solution.

To see a demo program, cd to ~cpsc/public_html/CPSC170A/hanoi and run the Towers program (java Towers).

Program Structure

You may organize your program in any way you like as long as it is clean, correct and reasonably efficient. Here are some suggestions: