Exploring Psychology Homepage
         
 

Tower of Hanoi Programming Notes by Andrew Linn

Known Problems: Sometimes a disk will "hang in midair" when placed on a stack. I know this is a flaw the way I programmed it, but I cannot find the error.

Notes:
I was given no specifics about this program beyond the rules of the game. I had no idea how it could be used in the venue of exploring psychology, so I had no idea of what measurements I should be looking for (number of mistakes, time taken to complete, time between moves, etc.). I just created the game. Since there were no requirements for things like indicating End of Game, Auto Play, or Hints, I didn't program for these features. One parameter I was given was to allow the player to choose the number of disks to use (up to 10). I decided to show them how many moves were required to complete the task and also how many moves they had taken.

To simplify the program control, I made 10 different scenarios for the program, one for each possible number of disks. Each disk was given a number 1 through 10. In Scenario 1, there is only one disk, disk #1. In Scenario 2, there are 2 disks, #1 and #2, and so on up to Scenario 10. There are 3 possible horizontal locations, the 3 posts of the game.

When the player click on a disk, that disk's number is recorded and the program checks to see if any higher numbered disk (smaller) has the same horizontal location (indicating a smaller disk is on top of the selected disk, the player is violating the Move Only One Disk At A Time rule).

If the selected disk is on top of the stack, the player is allowed to move it to another stack. Upon release, the program checks to see if there are any higher numbered (smaller) disks already on the destination stack, meaning the player is violating the No Larger Disk Can Sit On A Smaller Disk rule.

If the move is valid, the move count is incremented, if not, the disk is placed back in its original position

Original Director 8 source code if you have questions, please e-mail me at: alinn@willamette.edu

 
Site Map
Contact Us

 

Exploring Psychology Site

Background