Question
Create a C++ program for the following: Tower of Hanoi: A very popular mathematical game or puzzle is referred to as the Tower of Hanoi.
Create a C++ program for the following:
Tower of Hanoi: A very popular mathematical game or puzzle is referred to as the Tower of Hanoi. The idea behind the game is to find an efficient method for moving disks between three posts. Each disk has a different diameter, but all of them can be placed on the available posts. The goal of the game is to move all of the disks from one post to the another according the following rules:
1. Only one disk may be transferred at a time
2. Only the top disk on any post may be accessed at a given time
3. No disk may be placed on top of a smaller disk at any point
At the start of the game, all of the disks must originally be placed such that the largest disk is on the bottom of the stack of one post, and the smallest is on the top of the stack on the same post. The disks should form a cone shape. Write a program to simulate the Tower of Hanoi game. For each move print the post number (1 3) from which the disk is taken, the diameter of the disk, and the resulting post on which the disk is placed. Also, show the current diameter of the disks on each post. You must use stacks to solve this problem!
Complete the Tower of Hanoi solver and add the following features:
- Ask the user to indicate the number of disks
- After this, the following will happen:
- The puzzle will be drawn (using the bar function, for example), and the user will enter source and destination.
- If the move is invalid, alert the user to this fact.
- If the move is valid, move the disk and then draw the stacks again.
- Play continues until the user has all of the disks on the 3rd peg.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started