/////////////////////////Sk. Arif Ahmed//////////////////////////////////////
////////////////////////////2006////////////////////////////////////////////
////////======='''''''''''''''''''''''''''''''''========////////////////////
////////;;;;;;;;;;;;;;;;;;;;H.I.T;;;;;;;;;;;;;;;;;;;;;;; ////////////
//This program is designe for arranging and solving a BOSS Puzzle////////
////such as 1,2,3...................14,15///////////////////////////////////////
/* (C)opy right: Sk.A.Ahmed */
//<<<<<<<<<<<<<<<<<<<<Mail: [[Email Removed]]>>>>>>>>>>>>>>>>>>>>>///////
#include<dos.h>
#include<conio.h>
#include<stdio.h>
int record[5000],rec;
int row=3,colmn=3;//global blank reprasenttator
//array to inisialize 1st
int mainarr[5][5]={
{1,2,3,4},
{5,6,7,8},
{9,10,11,12},
{13,14,15,0}
};
int impos[5][5]={
{9,4,11,7},
{5,6,2,12},
{15,1,13,3},
{10,8,14,0}
};
int arr[5][5]={
{1,4,15,7},
{8,10,2,11},
{14,3,6,13},
{12,9,5,0}
};
int *node,*up,*down,*left,*right; //Pointer to denote node
size(ssl,esl)
int ssl,esl;
{
union REGS i,o;
i.h.ah=1;
i.h.ch=ssl;
i.h.cl=esl;
i.h.bh=0;
int86(16,&i,&o);
return;
}
void setvidio(int k)
{
if(k==0)
return;
textcolor(BLACK);
textbackground(WHITE);
return;
}
void resetvidio(int k)
{
if(k==0)
return;
textcolor(WHITE);
textbackground(BLACK);
return;
}
int menu() //Menu function
{
int i=175,j=0,k=0,hit,ans=1;
clrscr();
do{
clrscr();
gotoxy(38,9);
printf("Main Menu");
gotoxy(32,11);
printf("????????????????????");
gotoxy(32,12);
printf("? ?");
gotoxy(32,12);
printf("? ?");
gotoxy(32,13);
printf("? ?");
gotoxy(32,14);
printf("? ?");
gotoxy(32,15);
printf("????????????????????");
// size(32,0);
//clrscr();
gotoxy(35,12);
printf("%c",i);
gotoxy(36,12);
setvidio(i);
cprintf("EASY LEVEL ");
resetvidio(1);
size(32,1);
gotoxy(35,13);
printf("%c",j);
gotoxy(36,13);
setvidio(j);
cprintf("RANDOM LEVEL");
resetvidio(1);
size(32,2);
gotoxy(35,14);
printf("%c",k);
gotoxy(36,14);
setvidio(k);
cprintf("IMPOSSIBLE ");
resetvidio(1);
hit=getkey();
if(hit==80){
switch(ans){
case 1:
ans=2;
j=175;
i=k=0;
break;
case 2:
ans=3;
k=175;
i=j=0;
break;
}
}
if(hit==72){
switch(ans){
case 2:
ans=1;
i=175;
j=k=0;
break;
case 3:
ans=2;
j=175;
i=k=0;
break;
}
}
}while(hit!=28);
return ans;
}
//Report file
void report()
{
int a;
clrscr();
printf(" --------------------REPORT----------------------\n");
printf("------------------------------------------------------------\n");
printf("You are complite in %d move.\n",rec-1);
for(a=1;record[a]!=-1;a++){
printf("%d.Move: %d\n",a,record[a]);
if((a%20)==0){
printf("ENTER to continue...");
getch();
clrscr();
printf(" --------------------REPORT----------------------\n");
printf("------------------------------------------------------------\n");
printf("You are complite in %d move.\n",rec-1);
}
}
getch();
}
void win()
{
char arr[]="CONGRATULATION YOU HAVE OWN!!!!";
int i;
clrscr();
printf("\n\n\n\n\n ");
for(i=0;arr[i]!=NULL;i++){
printf("%c",arr[i]);
if(arr[i]!=' '){
sound(50);
delay(300);
nosound();
}
else
delay(500);
}
printf("\nPress ENTER to see Report.");
getch();
}
void help()
{
clrscr();
printf(" %c Help on BOSS Puzzle. %c\n",3,3);
printf("********************************************************************************");
printf(" Created By: Sk.Arif Ahmed.\n");
printf(" 2006 \n");
printf(" Haldia Institute Of Tecnology.\n");
printf("********************************************************************************\n");
printf(" %cSoftware Information:\n",3);
printf(" --------------------\n");
printf(" This is a game called BOSS Puzzle implimented in TURBO C platform ");
printf(" but can run in LINUX platform supported by ANSI C. Use you skill to");
printf(" solve in minimum move.\n\n");
printf(" %cInstruction:\n",3);
printf(" ------------\n");
printf(" Use arrow key to move and arrange the number as 1,2,3,....14,15.\n");
printf(" from left to right.\n");
printf(" %cCotact:\n",3);
printf(" -------\n");
printf(" Email: arif_hit @ rediffmail.com\n");
//printf("\n\n\n\nPress any key to continue....");
}
//Check if that is solved
int check()
{
int r=1,i,j,flag=1;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(r<=15){
if(arr[i][j]!=r)
flag=0;
}
r++;
}
}
if(flag==1){
record[rec]=-1;
win();
return 1;
}
else
return 0;
}
void print()
{
int i,j;
clrscr();
printf(" ????????????????????\n");
printf(" ? BOSS Puzzle ?\n");
printf(" ? %c ????? %c ?\n",1,2);
printf(" ? SK.A.Ahmed. ?\n");
printf(" ????????????????????\n\n");
printf("Press ENTER for Help, Press Esc for exit.\n\n\n\n");
printf(" ?????????????????????\n ? ") ;
for(i=0;i<4;i++){
for(j=0;j<4;j++){
if(arr[i][j]==0)
printf(" ");
else
printf("%d",arr[i][j]);
if(arr[i][j]<10)
printf(" ? ");
else
printf(" ? ");
}
if(i<3){
printf("\n ?");
printf("????????????????????");
}
if(i==3&&j==4)
printf("\n ?????????????????????") ;
else
printf("\n ? ");
}
}
//Function for getting key valu
int getkey()
{
union REGS i,o;
while(!kbhit());
i.h.ah=0;
int86(22,&i,&o);
if(o.h.ah==72){ //Sound genarator
sound(2500);
delay(150);
nosound();
}
if(o.h.ah==80){
sound(2800);
delay(150);
nosound();
}
if(o.h.ah==75){
sound(2500);
delay(150);
nosound();
}
if(o.h.ah==77){
sound(2800);
delay(150);
nosound();
}
return(o.h.ah);
}
void downfun() //down arrow key function
{
if(*up!=NULL){
if(arr[row-1][colmn]!=record[rec]){
record[rec]=arr[row-1][colmn];
rec++;
}
arr[row][colmn]=arr[row-1][colmn];
arr[row-1][colmn]=0;
row--;
}
}
void upfun()
{
if(*down!=NULL){
if(arr[row+1][colmn]!=record[rec]){
record[rec]=arr[row+1][colmn];
rec++;
}
arr[row][colmn]=arr[row+1][colmn];
arr[row+1][colmn]=0;
row++;
}
}
void leftfun()
{
if(*right!=NULL){
if(arr[row][colmn+1]!=record[rec]){
record[rec]=arr[row][colmn+1];
rec++;
}
arr[row][colmn]=arr[row][colmn+1];
arr[row][colmn+1]=0;
colmn++;
}
}
void rightfun()
{
if(*left!=NULL){
if(arr[row][colmn-1]!=record[rec]){
record[rec]=arr[row][colmn-1];
rec++;
}
arr[row][colmn]=arr[row][colmn-1];
arr[row][colmn-1]=0;
colmn--;
}
}
void assign(int flag)
{
int i,j,rnd;
if(flag==2){
for(i=0;i<4;i++)
for(j=0;j<4;j++)
arr[i][j]=mainarr[i][j];
for(i=0;i<500;i++){
rnd=rand()%4;
if(rnd==0)
leftfun();
else if(rnd==1)
rightfun();
else if(rnd==2)
upfun();
else
downfun();
if(colmn>0)
left=&arr[row][colmn-1];
else
left=NULL;
if(colmn<3)
right=&arr[row][colmn+1];
else
right=NULL;
if(row>0)
up=&arr[row-1][colmn];
else
up=NULL;
if(row<3)
down=&arr[row+1][colmn];
else
down=NULL;
}
}
if(flag==3){
for(i=0;i<5;i++)
for(j=0;j<5;j++)
arr[i][j]=impos[i][j];
}
rec=0;
}
int main()
{
int k=10,flag=0,choice;
choice=menu();
node=&arr[row][colmn];
up=&arr[row-1][colmn];
down=NULL;
left=&arr[row][colmn-1];
right=NULL;
assign(choice);
while(k!=1){
clrscr();
print();
flag=check();
if(flag==1){
k=1;
// win();
report();
getch();
exit(1);
}
k=getkey();
if(k==28){
help();
getch();
}
if(k==80)
downfun();
else if(k==72)
upfun();
else if(k==75)
leftfun();
else if(k==77)
rightfun();
if(colmn>0)
left=&arr[row][colmn-1];
else
left=NULL;
if(colmn<3)
right=&arr[row][colmn+1];
else
right=NULL;
if(row>0)
up=&arr[row-1][colmn];
else
up=NULL;
if(row<3)
down=&arr[row+1][colmn];
else
down=NULL;
print();
}
clrscr();
for(k=0;k<1040;k++)
printf("%c",3);
printf("\n Thanks for using BOSS Puzzle.\n\n");
for(k=0;k<1040;k++)
printf("%c",3);
getch();
return 0;
}