/* My record 122 moves*/ #include"conio.h" #include"stdlib.h" #include"dos.h" int a[4][4]={1,4,15,7,8,10,2,11,14,3,6,13,12,9,5,0},count=0,t,r=3,c=3,r1,c1; void main() { char ch; int r2,c2; highvideo();_setcursortype(_NOCURSOR); textbackground(6); clrscr(); printf("Written by A.V.Sharath\navsharath@yahoo.com"); gotoxy(25,10); printf("Welcome To The Number Game!\n\n\t\t\t Hit any key to start..."); getch(); clrscr(); gotoxy(16,7); printf("ÉÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍ»"); gotoxy(16,9); printf("ÌÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍ͹"); gotoxy(16,11);printf("ÌÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍ͹"); gotoxy(16,13);printf("ÌÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍÍÎÍÍÍÍÍÍÍÍ͹"); gotoxy(16,15);printf("ÈÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍͼ"); gotoxy(32,25);printf(" Hit End key To Quit"); gotoxy(32,24);printf(" Hit 's' To Start Shuffling.(any key to end)"); dispset(); ch=getch(); while(ch!=79) { r1=c1=0; ch=getch(); if(ch==72&&r<3)r1++;if(ch==80&&r>0)r1--; if(ch==75&&c<3)c1++;if(ch==77&&c>0)c1--; if(ch==115) shuffle(); if((r1+c1)!=0) { count++; sound(5000); delay(10); nosound(); t=a[r][c]; a[r][c]=a[r+r1][c+c1]; a[r+r1][c+c1]=t; r+=r1;c+=c1; dispset(); } } } dispset() { int k=1,result=0,i,j; for(i=0;i<4;i++) {for(j=0;j<4;j++) { gotoxy( (((j+1)*10)+6),(((i+1)*2)+6)); if(a[i][j]==0) printf("º "); else printf("º %2d",a[i][j]); if(a[i][j]==k) result++; k++;} printf(" º");} gotoxy(30,18); printf("Total moves: %d",count); gotoxy(30,19);printf("Correct positions:%2d",result); if(result==15) {gotoxy(25,17);printf("Congrats! You Finished in %d Moves",count);getch();clrscr();exit(1);} return; } shuffle() { while(!kbhit()) { c1=rand()%4; r1=rand()%4; t=a[r][c]; a[r][c]=a[r1][c1]; a[r1][c1]=t; r=r1; c=c1; dispset(); } r1=c1=0; return; }