Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE SEND ME THE C or C++ program of this project. DONT RUSH. ILL GIVE YOU A THUMBS UP ANYWAY. The Tower of Hanoi is

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

PLEASE SEND ME THE C or C++ program of this project. DONT RUSH. ILL GIVE YOU A THUMBS UP ANYWAY.

The Tower of Hanoi is a mathematical game for moving a set of N disks stacked in the order of decreasing size from one pile to another (using a spare pile) one disk at a time without ever placing a larger disk on top of a smaller disk. The No-Flyover Tower of Hanoi is derived from the Tower of Hanoi with the following modifications When a disk is moved, it is not allowed to jump over a smaller disk on the spare pile. Pile A Pile B (Spare) Pile C The algorithm for moving N disks in the original Tower of Hanoi game can best be described in a recursive manner as described below 1. Move the top N - 1 disks to a spare pile 2. Move the largest disk to the destination 3. Move the N - 1 disks from the spare pile to the destination The algorithm becomes a bit more complex for the No-fly-over Tower of Hanoi because The following is a core of the algorithm, but not the entire algorithm of the no flyover restriction when a disk is moved /move n disks from src to dst */ nf_hanoi (n, src, dst) nf_hanoi (n - 1, src, dst) move (src, tmp) nf_hanoi (n - 1, dst, src) /* tmp = spare pile */ move (NF Hanoi Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (NF Hanoi) Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (NF Hanol) Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (tmp, dst) nf_hanoi (n - 1, src, dst) The project consists of two parts: (1) to determine the minimum number of moves necessary for moving N disks from pile A to pile C; (2) to simulate the game (the details of which will be discussed in class). Note that the algorithm used for this project must be fully recursive. The number of moves it takes to complete a Tower of Hanoi game in the minimum number of steps can be calculated in a recursive manner as shown below. int hanoi (int n) if (n 1) return 1; else return 2 * hanoi(n-1) + 1 The number of moves required for a no-flyover Tower of Hanoi game would be different but can be calculated in a similar manner or directly from the simulation The following are the specific requirements for the project. 1. The source pile is A and the destination pile C. 2. Piles must be implemented as stacks as shown in Figure 1. The smallest disk is num- bered 1, and the largest N. At the bottom of each pile is a super large disk with size 255, which should not be moved and only exists there for the size comparison purpose. X5, X6, nd x7 are used as stack pointer registers for stacks A, B, and Stacks grow upward from lower memory address to higher. Fach item on the sta should be 8 byte X5 8 X7 Stack A Stack B Stack Figure 1: Piles A, B, and C with N-8. Initially all N disks are stacked on pile A in decreasing size order 3. Moving a disk from a pile to another requires popping an item off a stack and pushing it onto another stack as shown in Figure 2 X5 4 8 X7 Stack A Stack B Stack C Figure 2: A disk is moved from pile A to pile B 4. Figure 3 depicts the final states of the stacks after all of the moves are successfully completed X7 SP X5 SP Stack A Stack B Stack Figure 3: In the final state, all N disks are stacked on pile C in decreasing size order 5. A driver which contains the initial setup for stacks A, B, and C are provided in a separate file: nfhanoi-driver.s. The driver, after initializing the stacks, calls nfhanoi. Inputs to nfhanoi are the number of disks to move, N, and the names of source, destination, and temporary piles: 0 for pile A, 1 for B, and 2 for C. These are passed to nfhanoi via X0, X2, X3, and X4. Thus XO, X2, X3, and X4 contain N, 0, 2 and 1 respectively when nfhanoi is called initially. nfhanoi should return the number of moves made in X1 6. The driver file, nfhanoi-driver.s, includes a template for procedure move as well as helper procedures for debugging: errorS and errorF. move is used to move a disk from a pile to another. Source and destination pile names (again 0 for A, 1 for B, and 2 for C) are passed to procedure move via X2 and X3. move also keeps track of the running count of the total number of moves made and outputs it in X1. errorS and errorF return -1 and -2 respectively in X1 and stops the program execution when a size error or a flyover error has been detected. You should incorporate these two procedures in your code for debugging The Tower of Hanoi is a mathematical game for moving a set of N disks stacked in the order of decreasing size from one pile to another (using a spare pile) one disk at a time without ever placing a larger disk on top of a smaller disk. The No-Flyover Tower of Hanoi is derived from the Tower of Hanoi with the following modifications When a disk is moved, it is not allowed to jump over a smaller disk on the spare pile. Pile A Pile B (Spare) Pile C The algorithm for moving N disks in the original Tower of Hanoi game can best be described in a recursive manner as described below 1. Move the top N - 1 disks to a spare pile 2. Move the largest disk to the destination 3. Move the N - 1 disks from the spare pile to the destination The algorithm becomes a bit more complex for the No-fly-over Tower of Hanoi because The following is a core of the algorithm, but not the entire algorithm of the no flyover restriction when a disk is moved /move n disks from src to dst */ nf_hanoi (n, src, dst) nf_hanoi (n - 1, src, dst) move (src, tmp) nf_hanoi (n - 1, dst, src) /* tmp = spare pile */ move (NF Hanoi Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (NF Hanoi) Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (NF Hanol) Pile A Pile B (Spare) Pile C Pile A Pile B (Spare) Pile C move (tmp, dst) nf_hanoi (n - 1, src, dst) The project consists of two parts: (1) to determine the minimum number of moves necessary for moving N disks from pile A to pile C; (2) to simulate the game (the details of which will be discussed in class). Note that the algorithm used for this project must be fully recursive. The number of moves it takes to complete a Tower of Hanoi game in the minimum number of steps can be calculated in a recursive manner as shown below. int hanoi (int n) if (n 1) return 1; else return 2 * hanoi(n-1) + 1 The number of moves required for a no-flyover Tower of Hanoi game would be different but can be calculated in a similar manner or directly from the simulation The following are the specific requirements for the project. 1. The source pile is A and the destination pile C. 2. Piles must be implemented as stacks as shown in Figure 1. The smallest disk is num- bered 1, and the largest N. At the bottom of each pile is a super large disk with size 255, which should not be moved and only exists there for the size comparison purpose. X5, X6, nd x7 are used as stack pointer registers for stacks A, B, and Stacks grow upward from lower memory address to higher. Fach item on the sta should be 8 byte X5 8 X7 Stack A Stack B Stack Figure 1: Piles A, B, and C with N-8. Initially all N disks are stacked on pile A in decreasing size order 3. Moving a disk from a pile to another requires popping an item off a stack and pushing it onto another stack as shown in Figure 2 X5 4 8 X7 Stack A Stack B Stack C Figure 2: A disk is moved from pile A to pile B 4. Figure 3 depicts the final states of the stacks after all of the moves are successfully completed X7 SP X5 SP Stack A Stack B Stack Figure 3: In the final state, all N disks are stacked on pile C in decreasing size order 5. A driver which contains the initial setup for stacks A, B, and C are provided in a separate file: nfhanoi-driver.s. The driver, after initializing the stacks, calls nfhanoi. Inputs to nfhanoi are the number of disks to move, N, and the names of source, destination, and temporary piles: 0 for pile A, 1 for B, and 2 for C. These are passed to nfhanoi via X0, X2, X3, and X4. Thus XO, X2, X3, and X4 contain N, 0, 2 and 1 respectively when nfhanoi is called initially. nfhanoi should return the number of moves made in X1 6. The driver file, nfhanoi-driver.s, includes a template for procedure move as well as helper procedures for debugging: errorS and errorF. move is used to move a disk from a pile to another. Source and destination pile names (again 0 for A, 1 for B, and 2 for C) are passed to procedure move via X2 and X3. move also keeps track of the running count of the total number of moves made and outputs it in X1. errorS and errorF return -1 and -2 respectively in X1 and stops the program execution when a size error or a flyover error has been detected. You should incorporate these two procedures in your code for debugging

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

Students also viewed these Databases questions

Question

this is the uestion

Answered: 1 week ago