Code this classic puzzle game, "Tower of Hanoi" alongside Flash AS3 inwards 2011.
The Tower of Hanoi or Towers of Hanoi is a mathematical game or puzzle. It consists of iii rods, as well as a pose out of disks of unlike sizes which tin slide onto whatever rod. The puzzle starts alongside the disks inwards a keen stack inwards ascending lodge of size on 1 rod, the smallest at the top, hence making a conical shape. The objective of the puzzle is to motion the entire stack to or as well as so other rod.
Game rules
The game kickoff alongside 3 rods, A,B as well as C. Initially, all disks are stack on rod A, as well as y'all convey to motion all the disk inwards ascending lodge on rod C to win.
There are few criteria when moving the disk around.
- Only 1 disk tin travel motion at a time.
- Only the elevation nearly disk tin travel move.
- Disk tin exclusively travel placed on elevation of a larger disk.
Gameplay Programming
To code this game, nosotros tin purpose 3 arrays to stand upwards for the 3 rods, which comprise listing of values that stand upwards for all the disks. The bigger the disk, the larger the pose out (or the other fashion round, depend on how y'all produce the status disputation later).
Then, purpose array PUSH as well as POP component division to "move the disk around". In this case, the PUSH as well as POP component division travel just similar what nosotros want, removing as well as adding items from the elevation of the array/stack.
Last, purpose a status disputation to banking concern fit to come across if a disk tin travel motion on to or as well as so other rod base of operations on target rod elevation nearly disk size. To banking concern fit the elevation nearly disk size, merely POP it.
Recursive Solution
The puzzle tin travel solve automatically past times using a recursive component division too, which y'all tin read to a greater extent than inwards this page,
"Writing a Towers of Hanoi program".
Play The Game
You tin play "
Tower of Hanoi" inwards my deviantart. I convey include the recursive puzzle solving component division every bit well.
Reference
Tower of Hanoi Wikipedia Writing a Towers of Hanoi program Tower of Hanoi Game Deviantart