Computer Science Canada

I need some help with functions.

Author:  Silent Avenger [ Sun Nov 26, 2006 10:21 pm ]
Post subject:  I need some help with functions.

Okay I'm making a program that will solve the tower of hanoi game. I think I've got the proper function to solve it but I'm not quite sure how to output information on how to solve the game eg. move disk 1 to peg 2, move disk 2 to peg 3, move disk 1 to peg 3, etc.

if no one knows what I'm talking about here's a website with the game: http://www.cut-the-knot.org/recurrence/hanoi.shtml

Help with this would be greatly appreciated.

Author:  wtd [ Sun Nov 26, 2006 11:55 pm ]
Post subject: 

Care to show us the code you have, thus far?

Author:  Silent Avenger [ Mon Nov 27, 2006 8:08 am ]
Post subject: 

Oh right, sorry I forgot to post it. Okay here's the code I have so far:
code:
Private Function MoveTower(Disk As Integer, Source As Integer, Dest As Integer, Spare As Integer)
    If Disk = 0 Then
      MoveDisks Disk, Source, Dest
    Else
      MoveTower Disk - 1, Source, Spare, Dest
      MoveDisks Disk, Source, Dest
      MoveTower Disk - 1, Spare, Dest, Source
    End If
End Function

Private Sub Command1_Click()
MoveTower text1.Text
End Sub

Author:  wtd [ Mon Nov 27, 2006 8:35 am ]
Post subject: 

Cannot MoveDisks and/or MoveTower affect the value of some text field?

Author:  Silent Avenger [ Tue Nov 28, 2006 5:36 pm ]
Post subject: 

The value of the text field should not be affected though because it's the number of disks in the game.

Author:  cool dude [ Sun Dec 03, 2006 4:45 pm ]
Post subject: 

umm, i'm not to sure on what you were asking for help with. but i think this might help you quite a bit. (Scroll to the very bottom) http://www.ecoo.org/jketelaars/java2/java1.html

Author:  Silent Avenger [ Sun Dec 03, 2006 10:36 pm ]
Post subject: 

Okay thanks cool dude.

Author:  cool dude [ Sun Dec 03, 2006 11:09 pm ]
Post subject: 

Silent Avenger wrote:
Okay thanks cool dude.


haha i've been doing java all day and got mixed up with forums. sorry i gave you a link to your solution in java code. If you need any help translating the code just ask.

P.S. i had to write the pseudo code for Hanoi for one of my assignments just recently.

Author:  Silent Avenger [ Mon Dec 04, 2006 6:45 pm ]
Post subject: 

It's okay cool dude, I managed to figure it out with the help of the website.


: