Towr of Hanoi move the disc

This is a discussion on Towr of Hanoi move the disc within the C Programming forums, part of the General Programming Boards category; I already created the solver for the tower of hanoi. But I wanted to make a simple presentation of how ...

Towr of Hanoi move the disc

I already created the solver for the tower of hanoi. But I wanted to make a simple presentation of how the solver is working by showing the movement of the box as shown below. The problem I'm facing is:

How to make the program move the disk from tower-to-tower.
How the program will know which disk is the top, mid and bottom disk.
How the program will know which disk should go first to the other tower etc.....

where move single disk would include popping from the start stack and then pushing to finish stack, and each disk would be an ascii rectangle. All you have to do after that is display the stack in order.

Another option would be using a 2D array to represent each disk and instead of simply calling printf, have a function which displays the array in order.

2) If the position on the needle has a disc, it's easy to just print the needle (pole), while you are printing the disc. Print left half of the disc, print the needle, then print the right half. Or you can print all the disc, and then print the needle, last (not the other way around, though ).

3) There are vibrant colors in text mode, and it looks great with them. I believe cprintf() prints colors in Turbo/Borland C text mode, in Windows.

This truly challenging for me. Thank you for the algorithm, this is all I need to start coding this. I'll be posting my updated code just in case I experienced a problem. I'll be analyzing the algorithm as soon as I get home

where move single disk would include popping from the start stack and then pushing to finish stack, and each disk would be an ascii rectangle. All you have to do after that is display the stack in order.

Another option would be using a 2D array to represent each disk and instead of simply calling printf, have a function which displays the array in order.

So with the code sample that you showed to me, the tower will also move. So to animate the towers and disk both the tower and disk should move. I thought the only thing that will move are the disks.

Exactly, the only thing that will move is a single disk.
MoveTower is the recursive function and can only move a single disk at a time.
Think of it this way, to move of tower of 8 from Stack A - C with B as the temp stack, you first need to move a tower of 7 from the first to the temporary stack.

For that, you will first have to -

Move the tower of size 7 from A - B
Move the single remaining disk from from A - C
Move the tower of size 7 from B - C

...and so on till 7 reaches 1

Notice that the only line which does anything is 'Move the single remaining disk from from A - C', which would be the function which moves your rectangle.

If you have trouble grasping this implementation, try using it with char's first instead of the stack. Where the each tower would represent a char say, 'A' 'B' 'C' and n is the number of disks. In this version MoveSingleDisk() would simply print out the number of the disk and the start and finish destination.