Accueil > > > TOURS DE HANOI AVEC TURBO C ( GRAPHIQUE )
TOURS DE HANOI AVEC TURBO C ( GRAPHIQUE )
Information sur la source
Description
resolution graphique ; tours de hanoi pour toutes informations ou suggestions : yassou3@fr.fm merci pour votre interet et bonne chance.
Source
- #include <graphics.h>
- #include <stdlib.h>
- #include <stdio.h>
- #include <conio.h>
- #include <dos.h>
- struct rect{ /*declaration de la structure globale */
- int left1; /*qui contient les positions du rectangle*/
- int top1;
- int right1;
- int bottom1;
- int col;
- }p1;
-
- int x,p;
- int z=0;
- int j=0;
- int y=0;
- int max[8][5],left,right,top,bottom;
- void lignes();
- struct rect tab[3][20];
- int nc,x1=0,y1=0,z1=0,co,pos;
- char a1='a',b1='b',c1='c';
-
- // procedure de designe les lignes
- void lignes()
- {
- setcolor(getmaxcolor());
- int xmax=getmaxx(),ymax=getmaxy();
- line(xmax-800,ymax,xmax,ymax);
- line(xmax-540,ymax-350,xmax-540,ymax); //1er ligne
- line(xmax-300,ymax-350,xmax-300,ymax); //2eme ligne
- line(xmax-80,ymax-350,xmax-80,ymax); //3eme ligne
- }
- void deplacer1(char a1, char b1)
- {
-
- if(a1=='a') { pos=x1; if(x1>0) x1--; co=0; }
- if(a1=='b') { pos=y1; if(y1>0) y1--; co=1; }
- if(a1=='c') { pos=z1; if(z1>0) z1--; co=2; }
-
- p1=tab[co][pos];
-
- while(p1.bottom1>=getmaxy()-350) //du bas vers le haut
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1-=10;
- p1.bottom1-=10;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- //delay(50);
-
- }
- if((a1=='a')&&(b1=='b')) //de a vers b
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-300)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1+=1;
- p1.right1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(y1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
- if((a1=='a')&&(b1=='c')) //de a vers c
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-80)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1+=1;
- p1.right1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(z1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
-
- if((a1=='b')&&(b1=='a')) //de b vers a
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-540)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1-=1;
- p1.right1-=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(x1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
-
- if((a1=='b')&&(b1=='c')) //de b vers c
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-80)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1+=1;
- p1.right1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(z1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
-
- if((a1=='c')&&(b1=='b')) //de c vers b
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-300)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1-=1;
- p1.right1-=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(y1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
- if((a1=='c')&&(b1=='a')) //de c vers a
- {
- while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-540)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
-
- p1.left1-=1;
- p1.right1-=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- // delay(10);
- }
- while(p1.bottom1!=getmaxy()-(x1+2)*10)
- {
- setcolor(getmaxcolor()-15);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- p1.top1+=1;
- p1.bottom1+=1;
- setcolor(getmaxcolor()-p1.col);
- rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
- lignes();
- // delay(10);
- }
- }
- if(b1=='a') { x1++; tab[0][x1]=p1; }
- if(b1=='b') { y1++; tab[1][y1]=p1; }
- if(b1=='c') { z1++; tab[2][z1]=p1; }
-
- lignes();
-
- }
- // procedure Hanoi recursive
- void hanoi1(int nc,char a1,char b1,char c1)
- {
- if(nc==1) deplacer1(a1,b1);
- else
- {
- hanoi1((nc-1),a1,c1,b1);
- hanoi1(1,a1,b1,c1);
- hanoi1((nc-1),c1,b1,a1);
- }
- }
-
-
- void deplacer(int a,int c)
- {
- int i,n;
- if(a==1) p=x;
- if(a==4)
- {
- y--;
- p=y;
- }
- if(a==7)
- {
- z--;
- p=z;
- }
- max[c][j]-=40;
- for(i=0;i<(max[a][j]/20)-3;i++)
- {
- setcolor(getmaxcolor());
- ellipse(a*80, max[a][j]-i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80+1, max[a][j]-i*20,getmaxcolor());
- floodfill(a*80-1, max[a][j]-i*20,getmaxcolor());
- delay(10);
- ellipse(a*80,max[a][j]-i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-15);
- floodfill(a*80+1, max[a][j]-i*20,getmaxcolor());
- floodfill(a*80-1, max[a][j]-i*20,getmaxcolor());
- setcolor(getmaxcolor()-15);
- ellipse(a*80,max[a][j]-i*20,0,360,max[a+1][p],20);
- }
- if(a<c)
- {
- for(i=0;i<(c-a)*2;i++)
- {
- setcolor(getmaxcolor());
- ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
- delay(10);
- ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-15);
- floodfill(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
- setcolor(getmaxcolor()-15);
- ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- }
- for(i=0;i<(max[c][j]/20)-3;i++)
- {
- setcolor(getmaxcolor());
- ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- delay(10);
- ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-15);
- floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- setcolor(getmaxcolor()-15);
- ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
-
- }
- setcolor(getmaxcolor());
- ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- }
- if(a>c)
- {
- for(i=0;i<(a-c)*2;i++)
- {
- setcolor(getmaxcolor());
- ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80-i*40+1,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
- delay(10);
- ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-15);
- floodfill(a*80-i*40+1,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
- setcolor(getmaxcolor()-15);
- ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
- }
- for(i=0;i<(max[c][j]/20)-3;i++)
- {
- setcolor(getmaxcolor());
- ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- delay(10);
- ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-15);
- floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- setcolor(getmaxcolor()-15);
- ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- }
- setcolor(getmaxcolor());
- ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
- }
- max[a][j]+=40;
- if(c==4)
- {
- max[c+1][y]=max[a+1][p];
- y++;
- }
- if(c==7)
- {
- max[c+1][z]=max[a+1][p];
- z++;
- }
- if(c==1)
- {
- x++;
- max[c+1][x]=max[a+1][p];
- }
- if((a==1)&&(x>=0))
- {
- p--;
- x=p;
- }
- if(a==4)
- y=p;
- if(a==7)
- z=p;
- }
-
- void hanois(int a,int b,int c,int n)
- {
- if(n==1) deplacer(a,c);
- else
- {
- hanois(a,c,b,n-1);
- hanois(a,b,c,1);
- hanois(b,a,c,n-1);
- }
- }
-
-
- int main(void)
- {
- /* request auto detection */
- int gdriver = DETECT, gmode, errorcode;
- int i,n,m;
-
- initgraph(&gdriver, &gmode, "d:\\tc\\bgi");
- /* read result of initialization */
- errorcode = graphresult();
- if (errorcode != grOk)
- /* an error occurred */
- {
- printf("Graphics error: %s\n", grapherrormsg(errorcode));
- printf("Press any key to halt:");
- getch();
- exit(1); /* terminate with an error code */
- }
- printf("øøøøøøøøøøøøøøøøMENUøøøøøøøøøøøøøøø");
- printf("\n<1> travailler avec des Ellipses.");
- printf("\n<2> travailler avec des Barres 3D.");
- printf("\n<3> Quitter");
- printf("\n\nøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø");
- printf("\n\nentrer votre choix : ");
- scanf("%d",&m);
- switch(m)
- {
- case 1:{
- cleardevice();
- printf("\n\t\t\tentrer le nombre de disques n : ");
- scanf("%d",&n);
- cleardevice();
- line(80,getmaxy()-30,80,100);
- line(320,getmaxy()-30,320,100);
- line(560,getmaxy()-30,560,100);
- line(0,getmaxy()-30,getmaxx(),getmaxy()-30);
- outtextxy(80,getmaxy()-20,"A");
- outtextxy(320,getmaxy()-20,"B");
- outtextxy(560,getmaxy()-20,"C");
- int a=1;
- int b=4;
- int c=7;
- max[1][0]=400-(n-1)*40;
- max[4][0]=440;
- max[7][0]=440;
- for(i=0,x=0;i<n;i++)
- {
- ellipse(80, 400-i*40,0,360,80-i*10,20);
- setfillstyle(SOLID_FILL, getmaxcolor()-8);
- floodfill(81, 400-i*40,getmaxcolor());
- floodfill(79, 400-i*40,getmaxcolor());
- max[2][x]=80-i*10 ;
- x++;
- }
- x--;
- sleep(1);
- hanois(a,b,c,n);
- //cleardevice();
- sleep(1);
- cleardevice();
- outtextxy(200,160,"Merci pour votre visite");
- outtextxy(200,180,"Ecole Superieure de Technologie de Meknes(MAROC)");
- outtextxy(200,200,"Tours de Hanois ( Mini projet )");
- outtextxy(200,220,"R‚alis‚ par : ");
- outtextxy(200,240,"HICHAM et YASSINE");
- getch();
-
- return 0 ;
- }
- case 2: {
- cleardevice();
- printf("\n\t\t\tentrer le nombre de disques n : ");
- scanf("%d",&nc);
- getch();
- cleardevice();
- lignes();
- gotoxy(11,3); printf("DEBUT");
- gotoxy(42,3); printf("BUT");
- gotoxy(65,3); printf("INTERMEDIAIRE");
- left=getmaxx()-600,top=getmaxy()-17,right=getmaxx()-480,bottom=getmaxy()-10;
- /* designe des rectangles */
- for(i=0;i<nc;i++)
- {
- setcolor(getmaxcolor()-i);
- rectangle(left, top, right, bottom);
- p1.left1=left; p1.top1=top;
- p1.right1=right; p1.bottom1=bottom;
- p1.col=i;
- tab[0][x1]=p1; // stockage des variables de struct rect ds tab
- left+=5; top-=10;
- right-=5; bottom-=10;
- delay(1000);
- x1++;
- }
- x1--;
- hanoi1(nc,a1,b1,c1);
- /* clean up */
- getch();
- cleardevice();
- outtextxy(200,160,"Merci pour votre visite");
- outtextxy(200,180,"Ecole Superieure de Technologie de Meknes(MAROC)");
- outtextxy(200,200,"Tours de Hanois ( Mini projet )");
- outtextxy(200,220,"R‚alis‚ par : ");
- outtextxy(200,240,"HICHAM et YASSINE");
- getch();
- closegraph();
- return 0;
- break;
- }
- case 3: {
- cleardevice();
- outtextxy(200,190,"-----------------------");
- outtextxy(200,200,"MERCI POUR VOTRE VISITE");
- outtextxy(200,210,"-----------------------");
- getch();
- exit(0);
- }
- default : {
- printf("vous avez choisi de quitter");
- getch();
- exit(0);
- }
- }
- getch();
- closegraph();
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
struct rect{ /*declaration de la structure globale */
int left1; /*qui contient les positions du rectangle*/
int top1;
int right1;
int bottom1;
int col;
}p1;
int x,p;
int z=0;
int j=0;
int y=0;
int max[8][5],left,right,top,bottom;
void lignes();
struct rect tab[3][20];
int nc,x1=0,y1=0,z1=0,co,pos;
char a1='a',b1='b',c1='c';
// procedure de designe les lignes
void lignes()
{
setcolor(getmaxcolor());
int xmax=getmaxx(),ymax=getmaxy();
line(xmax-800,ymax,xmax,ymax);
line(xmax-540,ymax-350,xmax-540,ymax); //1er ligne
line(xmax-300,ymax-350,xmax-300,ymax); //2eme ligne
line(xmax-80,ymax-350,xmax-80,ymax); //3eme ligne
}
void deplacer1(char a1, char b1)
{
if(a1=='a') { pos=x1; if(x1>0) x1--; co=0; }
if(a1=='b') { pos=y1; if(y1>0) y1--; co=1; }
if(a1=='c') { pos=z1; if(z1>0) z1--; co=2; }
p1=tab[co][pos];
while(p1.bottom1>=getmaxy()-350) //du bas vers le haut
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1-=10;
p1.bottom1-=10;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
//delay(50);
}
if((a1=='a')&&(b1=='b')) //de a vers b
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-300)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1+=1;
p1.right1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(y1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if((a1=='a')&&(b1=='c')) //de a vers c
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-80)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1+=1;
p1.right1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(z1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if((a1=='b')&&(b1=='a')) //de b vers a
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-540)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1-=1;
p1.right1-=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(x1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if((a1=='b')&&(b1=='c')) //de b vers c
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-80)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1+=1;
p1.right1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(z1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if((a1=='c')&&(b1=='b')) //de c vers b
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-300)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1-=1;
p1.right1-=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(y1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if((a1=='c')&&(b1=='a')) //de c vers a
{
while(p1.left1-(p1.left1-p1.right1)/2!=getmaxx()-540)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.left1-=1;
p1.right1-=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
// delay(10);
}
while(p1.bottom1!=getmaxy()-(x1+2)*10)
{
setcolor(getmaxcolor()-15);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
p1.top1+=1;
p1.bottom1+=1;
setcolor(getmaxcolor()-p1.col);
rectangle(p1.left1,p1.top1,p1.right1,p1.bottom1);
lignes();
// delay(10);
}
}
if(b1=='a') { x1++; tab[0][x1]=p1; }
if(b1=='b') { y1++; tab[1][y1]=p1; }
if(b1=='c') { z1++; tab[2][z1]=p1; }
lignes();
}
// procedure Hanoi recursive
void hanoi1(int nc,char a1,char b1,char c1)
{
if(nc==1) deplacer1(a1,b1);
else
{
hanoi1((nc-1),a1,c1,b1);
hanoi1(1,a1,b1,c1);
hanoi1((nc-1),c1,b1,a1);
}
}
void deplacer(int a,int c)
{
int i,n;
if(a==1) p=x;
if(a==4)
{
y--;
p=y;
}
if(a==7)
{
z--;
p=z;
}
max[c][j]-=40;
for(i=0;i<(max[a][j]/20)-3;i++)
{
setcolor(getmaxcolor());
ellipse(a*80, max[a][j]-i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80+1, max[a][j]-i*20,getmaxcolor());
floodfill(a*80-1, max[a][j]-i*20,getmaxcolor());
delay(10);
ellipse(a*80,max[a][j]-i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-15);
floodfill(a*80+1, max[a][j]-i*20,getmaxcolor());
floodfill(a*80-1, max[a][j]-i*20,getmaxcolor());
setcolor(getmaxcolor()-15);
ellipse(a*80,max[a][j]-i*20,0,360,max[a+1][p],20);
}
if(a<c)
{
for(i=0;i<(c-a)*2;i++)
{
setcolor(getmaxcolor());
ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
delay(10);
ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-15);
floodfill(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
setcolor(getmaxcolor()-15);
ellipse(a*80+i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
}
for(i=0;i<(max[c][j]/20)-3;i++)
{
setcolor(getmaxcolor());
ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
delay(10);
ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-15);
floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
setcolor(getmaxcolor()-15);
ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
}
setcolor(getmaxcolor());
ellipse(a*80+(c-a)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80+(c-a)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80+(c-a)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
}
if(a>c)
{
for(i=0;i<(a-c)*2;i++)
{
setcolor(getmaxcolor());
ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80-i*40+1,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
delay(10);
ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-15);
floodfill(a*80-i*40+1,max[a][j]-((max[a][j]/20)-3)*20,getmaxcolor());
setcolor(getmaxcolor()-15);
ellipse(a*80-i*40,max[a][j]-((max[a][j]/20)-3)*20,0,360,max[a+1][p],20);
}
for(i=0;i<(max[c][j]/20)-3;i++)
{
setcolor(getmaxcolor());
ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
delay(10);
ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-15);
floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
setcolor(getmaxcolor()-15);
ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
}
setcolor(getmaxcolor());
ellipse(a*80-(a-c)*80,max[a][j]-((max[a][j]/20)-3)*20+i*20,0,360,max[a+1][p],20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(a*80-(a-c)*80+1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
floodfill(a*80-(a-c)*80-1,max[a][j]-((max[a][j]/20)-3)*20+i*20,getmaxcolor());
}
max[a][j]+=40;
if(c==4)
{
max[c+1][y]=max[a+1][p];
y++;
}
if(c==7)
{
max[c+1][z]=max[a+1][p];
z++;
}
if(c==1)
{
x++;
max[c+1][x]=max[a+1][p];
}
if((a==1)&&(x>=0))
{
p--;
x=p;
}
if(a==4)
y=p;
if(a==7)
z=p;
}
void hanois(int a,int b,int c,int n)
{
if(n==1) deplacer(a,c);
else
{
hanois(a,c,b,n-1);
hanois(a,b,c,1);
hanois(b,a,c,n-1);
}
}
int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
int i,n,m;
initgraph(&gdriver, &gmode, "d:\\tc\\bgi");
/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
/* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}
printf("øøøøøøøøøøøøøøøøMENUøøøøøøøøøøøøøøø");
printf("\n<1> travailler avec des Ellipses.");
printf("\n<2> travailler avec des Barres 3D.");
printf("\n<3> Quitter");
printf("\n\nøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø");
printf("\n\nentrer votre choix : ");
scanf("%d",&m);
switch(m)
{
case 1:{
cleardevice();
printf("\n\t\t\tentrer le nombre de disques n : ");
scanf("%d",&n);
cleardevice();
line(80,getmaxy()-30,80,100);
line(320,getmaxy()-30,320,100);
line(560,getmaxy()-30,560,100);
line(0,getmaxy()-30,getmaxx(),getmaxy()-30);
outtextxy(80,getmaxy()-20,"A");
outtextxy(320,getmaxy()-20,"B");
outtextxy(560,getmaxy()-20,"C");
int a=1;
int b=4;
int c=7;
max[1][0]=400-(n-1)*40;
max[4][0]=440;
max[7][0]=440;
for(i=0,x=0;i<n;i++)
{
ellipse(80, 400-i*40,0,360,80-i*10,20);
setfillstyle(SOLID_FILL, getmaxcolor()-8);
floodfill(81, 400-i*40,getmaxcolor());
floodfill(79, 400-i*40,getmaxcolor());
max[2][x]=80-i*10 ;
x++;
}
x--;
sleep(1);
hanois(a,b,c,n);
//cleardevice();
sleep(1);
cleardevice();
outtextxy(200,160,"Merci pour votre visite");
outtextxy(200,180,"Ecole Superieure de Technologie de Meknes(MAROC)");
outtextxy(200,200,"Tours de Hanois ( Mini projet )");
outtextxy(200,220,"R‚alis‚ par : ");
outtextxy(200,240,"HICHAM et YASSINE");
getch();
return 0 ;
}
case 2: {
cleardevice();
printf("\n\t\t\tentrer le nombre de disques n : ");
scanf("%d",&nc);
getch();
cleardevice();
lignes();
gotoxy(11,3); printf("DEBUT");
gotoxy(42,3); printf("BUT");
gotoxy(65,3); printf("INTERMEDIAIRE");
left=getmaxx()-600,top=getmaxy()-17,right=getmaxx()-480,bottom=getmaxy()-10;
/* designe des rectangles */
for(i=0;i<nc;i++)
{
setcolor(getmaxcolor()-i);
rectangle(left, top, right, bottom);
p1.left1=left; p1.top1=top;
p1.right1=right; p1.bottom1=bottom;
p1.col=i;
tab[0][x1]=p1; // stockage des variables de struct rect ds tab
left+=5; top-=10;
right-=5; bottom-=10;
delay(1000);
x1++;
}
x1--;
hanoi1(nc,a1,b1,c1);
/* clean up */
getch();
cleardevice();
outtextxy(200,160,"Merci pour votre visite");
outtextxy(200,180,"Ecole Superieure de Technologie de Meknes(MAROC)");
outtextxy(200,200,"Tours de Hanois ( Mini projet )");
outtextxy(200,220,"R‚alis‚ par : ");
outtextxy(200,240,"HICHAM et YASSINE");
getch();
closegraph();
return 0;
break;
}
case 3: {
cleardevice();
outtextxy(200,190,"-----------------------");
outtextxy(200,200,"MERCI POUR VOTRE VISITE");
outtextxy(200,210,"-----------------------");
getch();
exit(0);
}
default : {
printf("vous avez choisi de quitter");
getch();
exit(0);
}
}
getch();
closegraph();
}
Historique
- 04 décembre 2004 22:02:16 :
- a
- 04 décembre 2004 22:37:58 :
- a
- 04 décembre 2004 22:59:20 :
- a
- 04 décembre 2004 23:23:51 :
- a
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYSTECHDAYS PARIS 2012 : COMMENT SHAREPOINT A SAUVé MES TECHDAYS par ROMELARD Fabrice
Speakers : Lionel Limozin et Alain Marty La session commence par une découverte de SharePoint à travers la mise en place d'un environnement SharePoint pour la gestion des Sessions animées par BeWise. Le besoin est très ba...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0PERSPECTIVE 3.0 POUR SILVERLIGHT 5.0 par odewit
Je viens de publier la version 3.0 de Perspective pour Silverlight, qui regroupe un portage sous Silverlight 5.0 des fonctionnalités de Perspective 2.0, le framework 3D de haut-niveau introduit récemment et de nouveaux exemples de code. En voici la li...
Cliquez pour lire la suite de l'article par odewit TECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVERTECHDAYS PARIS 2012 : TOP 10 DES BEST PRACTICES POUR SQL SERVER par ROMELARD Fabrice
Speaker : Nadia Ben El Kadi Configuration machine La session commence par la toute première question à se poser lors de la mise en place d'environnement SQL Server, la configuration des machines : Type de mac...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SITECHDAYS PARIS 2012 : KINECT + OFFICE 365 UN BON GESTE POUR VOTRE SI par ROMELARD Fabrice
Speakers : Fabrice Barbin, Samuel Blanchard, Julien Lo Presti Titre Prometteur et attractif invitant à voir comment lier le composant ludique Kinect dans le cadre d'une structure IT classique, notamment au travers de la plat...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOURTECHDAYS PARIS 2012 : PLEINIèRE DU PREMIER JOUR par ROMELARD Fabrice
KeyNotes du premier jour pour les développeurs. La session est principalement axée sur une des principales directions prise par Microsoft à travers tous ses nouveaux produits : Cloud privé ou public (Solution Azure) ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : C++ RE : C++ par louis14
Cliquez pour lire la suite par louis14 C++ C++ par yesoun1
Cliquez pour lire la suite par yesoun1
Logiciels
Academy System (17.2.1.0)ACADEMY SYSTEM (17.2.1.0)Logiciel de gestion des établissements.
- élèves/étudiants (inscription, dossier, absence...)
-... Cliquez pour télécharger Academy System Easy-Planning (1.0.0.1)EASY-PLANNING (1.0.0.1)Basé sur les mêmes principes que MyPlanning, Easy-Planning permet de créer des plannings sous la ... Cliquez pour télécharger Easy-Planning COLLECTOR PLUS (3.00B)COLLECTOR PLUS (3.00B)COLLECTOR PLUS version 3.00B est un logiciel utilisant une base de données alimentée par :
- L... Cliquez pour télécharger COLLECTOR PLUS PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO (V7.4)PONAMEDIA TV DEVIENS HELLLOOO FLASH
LA TV SUR VOTRE ORDINATEUR.
Toute une plateforme Multi... Cliquez pour télécharger PONAMEDIA PREMIUM - HELLLOOO FLASH DEMO LettresFaciles 2011 (8.0.0.1)LETTRESFACILES 2011 (8.0.0.1)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011
|