#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define max 5
int tckt1[max][max],tckt2[max][max],tckt[max*max];
char ctckt1[max][max],ctckt2[max][max];
void create_tckt(char ctckt[max][max],int tkt[max][max])
{
int a,j=0;
int flg;
for(int i=0;i<max*max;i++)
{
do
{
flg = 0;
do
{
a = rand() % 26;
}while(a==0);
for(int k=0;k<i;k++)
{
if(a == tckt[k])
{ flg = 1; break; }
}
if(flg == 0)
tckt[i] = a;
}while(flg==1);
}
cout<<endl;
int l = 0;
for(i=0;i<max;i++)
{
for(j=0;j<max;j++)
{
tkt[i][j] = tckt[l];
ctckt[i][j] = ' ';
l++;
}
}
}
void disp_tckt(char ctckt[max][max],int tkt[max][max])
{
for(int i=0;i<max;i++)
{
cout<<"\n\n";
for(int j=0;j<max;j++)
{
printf("%3d%c",tkt[i][j],ctckt[i][j]);
}
}
}
void search(int num, int tckt[max][max], char ctckt[max][max])
{
int flag = 0;
for(int i=0;i<max;i++)
{
for(int j=0;j<max;j++)
{
if(tckt[i][j] == num)
{
ctckt[i][j] = '*';
flag = 1; break;
}
}
}
if(flag == 1)
cout<<"\n\nthe Elemenbt has been found !!";
else
cout<<"\n\nthe element has not been found !!";
cout<<"\n\n After draw of the new element ur ticket : \n";
disp_tckt(ctckt,tckt);
}
int chk_bingo(char ctkt[max][max])
{
int cnt;
for(int i=0;i<max;i++)
{
cnt = 0;
for(int j=0;j<max;j++)
{
if(ctkt[i][j] == '*')
cnt++;
}
if(cnt == 5)
return 1;
}
for(i=0;i<max;i++)
{
cnt = 0;
for(int j=0;j<max;j++)
{
if(ctkt[j][i] == '*')
cnt++;
}
if(cnt == 5)
return 1;
}
cnt = 0;
for(i=0;i<max;i++)
{
if(ctkt[i][i] == '*')
cnt++;
}
if(cnt == 5)
return 1;
cnt = 0;
for(i=0;i<max;i++)
{
if(ctkt[i][max-1-i] == '*')
cnt++;
}
if(cnt == 5)
return 1;
return 0;
}
int game(char ctckt1[max][max],int tckt1[max][max],char ctckt2[max][max],int tckt2[max][max])
{
int num[max*max];
int ns=0;
int res1,res2;
int a,flg;
for(int j=0;j<max*max;j++)
{
getch(); clrscr();
do
{
flg = 0;
do
{
randomize();
a = rand() % 26;
}while(a==0);
for(int i=0;i<ns;i++)
{
if(a == num[i])
{ flg = 1; break; }
}
if(flg == 0)
{ num[ns] = a; ns++; }
}while(flg == 1);
cout<<"\n\n the List so far :";
for(int i=0;i<ns;i++)
cout<<" "<<num[i];
search(a,tckt1,ctckt1);
getch();
search(a,tckt2,ctckt2);
getch();
res1 = chk_bingo(ctckt1);
res2 = chk_bingo(ctckt2);
if(res1==1)
return 1;
else if (res2 == 1)
return 2;
else if(res1 == 1 && res2 == 1)
return 3;
}
}
void main()
{
clrscr();
int result;
create_tckt(ctckt1,tckt1);
disp_tckt(ctckt1,tckt1);
cout<<"\n\n";
create_tckt(ctckt2,tckt2);
disp_tckt(ctckt2,tckt2);
result = game(ctckt1,tckt1,ctckt2,tckt2);
if (result == 1)
cout<<"\n\nPLAYER 1 WINS";
else if (result == 2)
cout<<"\n\nPLAYER 2 WINS";
else
cout<<"\n\nDRAW";
getch();
}
No comments:
Post a Comment