Solution to Hanoi Tower Game Through Raptor Programming

10
Design a program to graphically show how to play Hanoi Tower Game ICS Final Project Report Mohamed Khalid Khwaja (孟孟) Student ID: 2013431000 Class ID: 01101301 Country: Bangladesh (孟孟孟孟) Email: [email protected] Email: [email protected]

Transcript of Solution to Hanoi Tower Game Through Raptor Programming

Design a program to graphically show how to play Hanoi Tower GameICS Final Project Report

Mohamed Khalid Khwaja (孟孟)Student ID: 2013431000Class ID: 01101301

Country: Bangladesh (孟孟孟孟)Email: [email protected]

Email: [email protected]

Design a program to graphically show how to playHanoi Tower Game

Department of AeronauticsNorthwestern Polyechnical University, Xi’an, Shaanxi,

China

2

Design a program to graphically show how to playHanoi Tower Game

Subject Description Hanoi Tower is a very famous game. Basically the tower of Hanoialso called as the tower of Brahma or Lucas’ Tower. It is kind ofa puzzle game. It has one long horizontal base and three verticalrods. It has also a number of disks which can slide onto any ofthe three rods. The objective of the puzzle is to move the wholestack to the destination road. It always follows these rules,

1. Only one disk can be moved at the moment.2. Every single move consists of taking the upper disk from one

of the rods and sliding it onto another rod. The disk needsto put onto other disks that can be already present on thedestination rod.

3. No disk can be placed on top of a smaller disk. This willmake a conical shape at the end of the day.

Here we can level three rods as A (source Rod), B (intermediateRod) & C (destination). We have to work on it in our program. Wehave to Display the solution with Raptor programming.

Solutions There are various kinds of solution. I worked on a recursive solutionwith raptor programming. I can divide the solution in two parts. Firstone is to represent the function of Hanoi Tower and procedure of workand Second part is to display the solution to the Hanoi tower problemin a Graphic interface.

I have used Array, Input and Output to a file; I have also usedsubchart and procedure to solve the problem with Raptor.

Solution to the function of Hanoi Tower and procedure of work:Array- This is an Array I have used here to solve the problem. Array is acollection of variables with same name but the variables can be accessedindividually by using an index. In this problem we have used array to findthe uppermost Plate.

3

Design a program to graphically show how to playHanoi Tower Game

Input & Output- Input and output is a part which shows the program step bystep.

Subchart- Sometimes we need to perform same steps again and again. Weoften copy and paste these steps. But it makes the program look huge! Sohere is a solution to avoid the situation. We can make those steps assubchart and just use a Call to use the subchart.In this program, we have used one subchart named as ‘hanoi1’ to avoidcopying some steps again and again.

4

Design a program to graphically show how to playHanoi Tower Game

We have used a Call to load this subchart in the main. Here is the picture. The red arrow is indicating the call here.

Recursive solution Procedure- This part is one of the most important partsin this program because I didn’t use the Non-Recursive solution here. By changing output option here we can change the destination rod easily.

5

Design a program to graphically show how to playHanoi Tower Game

We have made this recursive program as a Procedure leveled as ‘Hanoi’. Thearrow indicates the procedure. We can call this procedure in the main orSubchart as well. In this program we have used a Call to use the procedurein the ‘hanoi1’ Subchart. Here the arrow indicates the call.

Solution to the Hanoi tower problem in a Graphic Interface-This is a Fundamental requirement of our ICS Final Project. In this part I

6

Design a program to graphically show how to playHanoi Tower Game

won’t go through any introduction. Let’s come to the point.

This Picture shows how to make the disks of Hanoi tower and find the exactposition by the help of Array. This will give us an output as a GraphicInterface.

The picture, given below is the process to draw the disks to the rightposition and graphically we can see the moving disks because of this part.Here in this program, we have used six programs like this part torepresent the movement of six disks in a correct way

7

Design a program to graphically show how to playHanoi Tower Game

Finally it looks like the following picture, when we play the program,

My Experience in Solving this Problem-

8

Design a program to graphically show how to playHanoi Tower Game

I have divided this project in few parts to make it simple and easy.This project is really complicated if I didn’t separate it into parts,it might look so difficult. And a single mistake could cause the wholeprogram failed.I have faced so many difficulties to figure it out the movement.Specially making the arrays were so tough. But as we worked as a groupafter spending three hours spontaneously we got the exact solution. Wehave spent almost sixteen hours and out sixteen hours we worked eighthours continuously to make the project what it looks like now. Still Icouldn’t make the graphic Interface 100% ok. But I am not getting it,why I couldn’t. I feel sorry for this.

Results and AnalysisWe have many ways to solve the problem. But in my opinion this way is the bestand easy way to solve this kind of problems. Here is my analysis-

No.

Analysis Advantages Weakness

1. I have made the programto find the perfect placefor a single disk withinthree steps; moving up,moving sideward and

moving down

It is very clearand easy to

understand howthe disks are

working.

Graphical Interface is notworking properly. Sometimesthe rod is appearing overthe disks; sometimes therod is disappearing if the

disk is moving.2. We can use loops and math

method. We can findsolution any with any

variable.

This method hasmade the programable to findsolution for

Infinite disks.

This makes the program lookso large!!

3. If we want to send ‘n’number of disks from thesource rod to destinationrod, we need 2n-1 steps.Example: for 6 disks we

need 25 =64 steps

Very clear andeasy counting.

The more number of disksthe more time we need.

4. We have used recursivesolution here, which is

really effective.

This shows thepower ofrecursion.

If we cannot use thecorrect program, incorrect

recursive may createinfinite loops.

5. This method is better We can find If we cannot use the

9

Design a program to graphically show how to playHanoi Tower Game

than Non-recursivesolution.

Infinite Diskssolution throughrecursion with ashort recursion

program.

correct program, incorrectrecursive may create

infinite loops.

6. Recursive solution iseasier than Non-recursive

solution.

Recursion oftenmakes key insightwhich makes theprogram simpler.

If we cannot use thecorrect program, incorrect

recursive may createinfinite loops.

ConclusionIt was really a very difficult task to do. But after completing thetask I have gained a huge level of confidence. I learnt how to usethe Recursion to solve exclusive and complicated problems like this.I came to know how Array helps us to solve a program. I am now verymuch confident to solve the program of Raptor. It enhanced my workcapability. After finishing this I jumped and shouted and with ourentire group celebrated the finishing.It was a great opportunity learning Raptor and I am sure in ourfuture life it will give us great benefits. I have almost done all the work because my group mates are littleunknown to Raptor. I worked very carefully on the graphicalinterface. I have added the music to decorate the project. The mostdifficult was to spend eight hours continuously.

Reference ICS Book by Xiuwei Zhang, Yanning Zhang Wikipedia Raptor Help.

10