-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtower_of_Hanoi.cpp
More file actions
250 lines (210 loc) · 4.99 KB
/
tower_of_Hanoi.cpp
File metadata and controls
250 lines (210 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#include <conio.h>
#include <graphics.h>
#include <stdio.h>
void outline()
{
// Main Base
line(100, 600, 1100, 600);
// 1st Line
line(300, 600, 300, 300);
// 2nd Line
line(600, 600, 600, 300);
// 3rd Line
line(900, 600, 900, 300);
// Printing Message
settextstyle(8, 0, 2);
outtextxy(290, 620, "(1)");
outtextxy(590, 620, "(2)");
outtextxy(890, 620, "(3)");
}
// Function for moving the Green Disk
// to Third Tower On Top Of Blue Disk
void p7()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "7th Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(850, 500, 950, 550);
floodfill(855, 545, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(875, 450, 925, 500);
floodfill(880, 495, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(825, 600, 975, 550);
floodfill(830, 555, 15);
// Calling outline() function
outline();
}
// Function to find the moving the Blue
// Disk To Third Tower On Top Of Red Disk
void p6()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "6th Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(850, 500, 950, 550);
floodfill(855, 545, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(275, 600, 325, 550);
floodfill(280, 595, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(825, 600, 975, 550);
floodfill(830, 555, 15);
// Calling outline() function
outline();
}
// Function to find the moving Green Disk
// To the First Tower
void p5()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "5th Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(550, 550, 650, 600);
floodfill(555, 595, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(275, 600, 325, 550);
floodfill(280, 595, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(825, 600, 975, 550);
floodfill(830, 555, 15);
// Calling outline() function
outline();
}
// Moving Red Disk To Third Tower
void p4()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "4th Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(550, 550, 650, 600);
floodfill(555, 595, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(575, 500, 625, 550);
floodfill(580, 545, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(825, 600, 975, 550);
floodfill(830, 555, 15);
// Calling outline() function
outline();
}
// Function for moving the Green Disk
// To Second Tower On Top Of Blue Disk
void p3()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "3rd Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(550, 550, 650, 600);
floodfill(555, 595, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(575, 500, 625, 550);
floodfill(580, 545, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(225, 550, 375, 600);
floodfill(230, 590, 15);
// Calling outline() function
outline();
}
// Function for moving the Blue Disk
// To Second Tower
void p2()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "2nd Phase");
setfillstyle(SOLID_FILL, BLUE);
rectangle(550, 550, 650, 600);
floodfill(555, 595, 15);
setfillstyle(SOLID_FILL, GREEN);
rectangle(875, 600, 925, 550);
floodfill(880, 595, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(225, 550, 375, 600);
floodfill(230, 590, 15);
// Calling outline() function
outline();
}
// Function for moving the Green Disk
// To Third Tower
void p1()
{
getch();
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "1st Phase");
setfillstyle(SOLID_FILL, GREEN);
rectangle(875, 600, 925, 550);
floodfill(880, 595, 15);
setfillstyle(SOLID_FILL, RED);
rectangle(225, 550, 375, 600);
floodfill(230, 590, 15);
setfillstyle(SOLID_FILL, BLUE);
rectangle(250, 500, 350, 550);
floodfill(255, 545, 15);
// Calling outline() function
outline();
}
// Function to start the animations
void start()
{
// Starting Condition
cleardevice();
settextstyle(8, 0, 4);
outtextxy(500, 50, "Beginning State");
// Red Coloring Of Disk
setfillstyle(SOLID_FILL, RED);
rectangle(225, 550, 375, 600);
floodfill(230, 590, 15);
// Blue Coloring Of Disk
setfillstyle(SOLID_FILL, BLUE);
rectangle(250, 500, 350, 550);
floodfill(255, 545, 15);
// Green Coloring Of Disk
setfillstyle(SOLID_FILL, GREEN);
rectangle(275, 450, 325, 500);
floodfill(285, 495, 15);
// calling outline() function
outline();
}
// Function to print the outlines of
// the animations
// Driver Code
int main()
{
int gd = DETECT, gm;
// Initialize of gdriver with
// DETECT macros
initgraph(&gd, &gm, "C:\\turboc3\\bgi");
// Calling start() function
start();
// Calling p1() function
p1();
// Calling p2() function
p2();
// Calling p3() function
p3();
// Calling p4() function
p4();
// Calling p5() function
p5();
// Calling p6() function
p6();
// Calling p7() function
p7();
// Holding screen for a while
getch();
// Close the initialized gdriver
closegraph();
}