#include<windows.h>
#include<iostream>
using namespace std;
int card[9],usercard[7],comcard[7],cardsuit[9];
void winner();
void highest();
void gotoxy(int x,int y)
{
COORD CursorPosition;
CursorPosition.X=x;
CursorPosition.Y=y;
SetConsoleCursorPosition((GetStdHandle(STD_OUTPUT_HANDLE)),CursorPosition);
}
void decone(int num,int x,int y)
{
int i;
char suit;
if(num<15)
{
suit=3;
}
else if(num>14 && num<28)
{
suit=4;
num=num-13;
}
else if(num>27 && num<41)
{
suit=5;
num=num-26;
}
else if(num>40 && num<54)
{
suit=6;
num=num-39;
}
else if(num==100 || num==101)
{
suit=0;
}
for(i=0;i<100000000;i++);
gotoxy(x,y);
for(i=0;i<11;i++)
{
cout<<"*";
}
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*  "<<suit;
gotoxy(x+7,y);
cout<<suit<<"  *";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*";
if(num==11)
{
gotoxy(x+5,y);
cout<<"J";
}
else if(num==12)
{
gotoxy(x+5,y);
cout<<"Q";
}
else if(num==13)
{
gotoxy(x+5,y);
cout<<"K";
}
else if(num==14)
{
gotoxy(x+5,y);
cout<<"A";
}
else if(num>1 && num<11)
{
gotoxy(x+5,y);
cout<<num;
}
else if(num==100)
{
gotoxy(x+3,y);
cout<<"Card A";
}
else if(num==101)
{
gotoxy(x+3,y);
cout<<"Card B";
}
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
cout<<"*  "<<suit;
gotoxy(x+7,y);
cout<<suit<<"  *";
y++;
gotoxy(x,y);
cout<<"*";
gotoxy(x+10,y);
cout<<"*";
y++;
gotoxy(x,y);
for(i=0;i<11;i++)
{
cout<<"*";
}
cout<<endl;
}
main()
{
m:
int choice,i,k,out=4,x=7,round=7,count=0,cont;
srand(time(0));
for(i=0;i<9;i++)
{
card[i]=rand()%52+2;
for(k=0;k<i;k++)
{
if(card[i]==card[k])
{
card[i]=rand()%52+2;
k=0;
}
}
}

decone(100,25,0);
decone(101,39,0);
decone(card[2],25,26);
decone(card[3],39,26);
l:
gotoxy(0,38);
cout<<"Enter the choice\n";
cout<<"1. Check\t2. Fold\n";
cin>>choice;
gotoxy(0,40);
cout<<"     ";
switch(choice)
{
case 1:
{
gotoxy(0,41);
cout<<"                               ";
for(int i=out;i<round;i++)
{
decone(card[i],x,13);
x=x+14;
}
out=round;
round++;
count++;
break;
}
case 2:
{
gotoxy(0,41);
cout<<"                               ";
goto n;
break;
}
default:
{
gotoxy(0,41);
cout<<"Choose from above choice only\n";
break;
}
}
if(count<3)
goto l;
else if(count==3)
{
gotoxy(28,4);
cout<<"      ";
gotoxy(42,4);
cout<<"      ";
decone(card[0],25,0);
decone(card[1],39,0);
winner();
}
n:
gotoxy(0,40);
cout<<"Press 1 to continue\n";
cin>>cont;
if(cont==1)
{
system("cls");
goto m;
}
else
exit(0);
system("pause");
}
void winner()
{
int i,j,k,t,temp,comcountflush[7]={0,0,0,0,0,0,0},usercountflush[7]={0,0,0,0,0,0,0},checkuser,checkcom;
int userpair=0,usertrip=0,compair=0,comtrip=0,userquad=0,comquad=0,userflush=0,comflush=0;
int comquadcard=0,userquadcard=0,comtripcard=0,usertripcard=0,userpaircard[2]={0,0},compaircard[2]={0,0},userpairno=0,compairno=0;
int userstraight=0,comstraight=0,straightusercount=0,straightcomcount=0,userstraightcard=0,comstraightcard=0,comflushhighcard=60,userflushhighcard=61;
int usersuit[7],comsuit[7],tempsuit,userflushcard,comflushcard;
int comstraightflushcount=0,comstraightflush,userstraightflushcount=0,userstraightflush;
for(i=0;i<9;i++)
{
if(card[i]<15)
cardsuit[i]=3;
else if(card[i]>14 && card[i]<28)
{
card[i]=card[i]-13;
cardsuit[i]=4;
}
else if(card[i]>27 && card[i]<41)
{
card[i]=card[i]-26;
cardsuit[i]=5;
}
else if(card[i]>40 && card[i]<54)
{
card[i]=card[i]-39;
cardsuit[i]=6;
}
}
for(i=0;i<2;i++)
{
usercard[i]=card[i+2];
usersuit[i]=cardsuit[i+2];
comcard[i]=card[i];
comsuit[i]=cardsuit[i];
}
for(i=4,k=2;i<9;i++,k++)
{
usercard[k]=card[i];
usersuit[k]=cardsuit[i];
comcard[k]=card[i];
comsuit[k]=cardsuit[i];
}
for(i=0;i<6;i++)
{
for(j=i+1;j<7;j++)
{
if(usercard[i]>usercard[j])
{
temp=usercard[i];
usercard[i]=usercard[j];
usercard[j]=temp;
tempsuit=usersuit[i];
usersuit[i]=usersuit[j];
usersuit[j]=tempsuit;
}
if(comcard[i]>comcard[j])
{
temp=comcard[i];
comcard[i]=comcard[j];
comcard[j]=temp;
tempsuit=comsuit[i];
comsuit[i]=comsuit[j];
comsuit[j]=tempsuit;
}
}
}
for(i=0;i<7;i++)
{
checkcom=comsuit[i];
comcountflush[checkcom]++;
checkuser=usersuit[i];
usercountflush[checkuser]++;
}
for(i=3;i<7;i++)
{
if(comcountflush[i]==5)
{
comflushcard=i;
comflush=1;
}
if(usercountflush[i]==5)
{
userflushcard=i;
userflush=1;
}
}
for(i=6;i>0;i--)
{
if(i>2)
{
straightusercount=0;
straightcomcount=0;
j=i;
k=0;
t=0;
while(j>=0)
{
j--;
if(usercard[j]!=usercard[j+1] && j>=0)                             /* straight */
{
k++;
if(usercard[i]==(usercard[j]+k))
straightusercount++;
}
if(straightusercount==4 && userstraight<1)
{
userstraight=1;
userstraightcard=usercard[i];
}
if(straightusercount==3 && userstraight<1 && usercard[i]==5 && usercard[6]==14)
{
userstraight=1;
userstraightcard=usercard[i];
}
if(comcard[j]!=comcard[j+1] && j>=0)
{
t++;
if(comcard[i]==(comcard[j]+t))
straightcomcount++;
}
if(straightcomcount==4 && comstraight<1)
{
comstraight=1;
comstraightcard=comcard[i];
}
if(straightcomcount==3 && comstraight<1 && comcard[i]==5 && comcard[6]==14)
{
comstraight=1;
comstraightcard=usercard[i];
} 
}
}
if(usercard[i]==usercard[i-1] && userpair<2)
{
userpair++;
userpaircard[userpairno]=usercard[i];                                                               /* pair */
if(usercard[i]==usercard[i-2] && i>1 && usertrip<1)
{
usertrip++;
userpair=userpair-2;                                                     /* trip */
usertripcard=usercard[i];
if(usercard[i]==usercard[i-3] && i>2)
{
userquad++;
userpair++;            
usertrip=usertrip-2;                                                  /* quad */
userquadcard=usercard[i];
}
}
if(usercard[i]!=usertripcard)
userpairno++;
}
if(comcard[i]==comcard[i-1] && compair<2)
{
compair++;
compaircard[compairno]=comcard[i];
if(comcard[i]==comcard[i-2] && i>1 && comtrip<1)
{
comtrip++;
compair=compair-2;
comtripcard=comcard[i];
compairno=compairno-2;
if(comcard[i]==comcard[i-3] && i>2)
{
comquad++;
compair++;
comtrip=comtrip-2;
comquadcard=comcard[i];
}
}
if(comcard[i]!=comtripcard)
compairno++;
}
}
if((comstraight==1 && comflush==1) || (userstraight==1 && userflush==1))
{
k=0;
comstraightflush=comstraightcard;
userstraightflush=userstraightcard;
for(i=6;i>=0;i--)
{
for(j=6;j>=0;j--)
{
if(comcard[j]==comstraightflush-k && comsuit[j]==comflushcard)
comstraightflushcount++;
if(usercard[j]==userstraightflush-k && usersuit[j]==userflushcard)
userstraightflushcount++;
}
k++;
}
if(comstraightflush==5)
{
if(comsuit[6]==comflushcard)
comstraightflushcount++;
}
if(userstraightflush==5)
{
if(usersuit[6]==userflushcard)
userstraightflushcount++;
}
}
if(comstraightflushcount==5)
cout<<"Computer wins : Straight flush";
else if(userstraightflushcount==5)
cout<<"User wins : Straight flush";
else if(comquad==1 || userquad==1)
{
if(comquad==1 && comquadcard>userquadcard)
cout<<"Computer wins : Four of a kind";
else if(userquad==1 && userquadcard>comquadcard)
cout<<"User wins : Four of a kind";
else 
highest();
}
else if((comtrip==1 && compair>0) || (usertrip==1 && userpair>0))
{
if(comtrip==1 && compair>0 && comtripcard>usertripcard)
cout<<"Computer wins : Full house";
else if(usertrip==1 && userpair>0 && usertripcard>comtripcard)
cout<<"User wins : Full house";
else if(userpaircard[0]>compaircard[0])
cout<<"User wins : High Full house";
else if(compaircard[0]>userpaircard[0])
cout<<"Computer wins : High Full house";
else
cout<<"Draw : Full house";
}
else if(userflush==1 || comflush==1)
{
if(userflush==1 && comflush!=1)
cout<<"User wins : Flush";     
else if(userflush!=1 && comflush==1)
cout<<"Computer wins : Flush";
else if(userflush==1 && comflush==1)
{
for(i=6;i>1;i--)
{
if(usersuit[i]==userflushcard && userflushhighcard!=comflushhighcard || userflushhighcard>usercard[i])
userflushhighcard=usercard[i];
if(comsuit[i]==comflushcard && comflushhighcard!=userflushhighcard && comflushhighcard>comcard[i])
comflushhighcard=comcard[i];
}
if(comflushhighcard>userflushhighcard)
cout<<"Computer wins : High Flush";
else if(userflushhighcard>comflushhighcard)
cout<<"User wins : High Flush";
else 
cout<<"Draw Flush";
}
}         
else if(userstraight==1 || comstraight==1)
{
if(userstraightcard>comstraightcard)
cout<<"User wins: Straight";
else if(comstraightcard>userstraightcard)
cout<<"Computer wins: Straight";
else if(comstraightcard==userstraightcard)
cout<<"Draw Straight";
}
else if(comtrip>0 || usertrip>0)
{
if(comtrip>0 && comtripcard>usertripcard)
cout<<"Computer wins : Three of a kind";
else if(usertrip>0 && usertripcard>comtripcard)
cout<<"User wins : Three of a kind";
else
highest();
}
else if(compair>0 || userpair>0)
{
if(compair>userpair)
cout<<"Computer wins : "<<compair<<" Pair";
else if(userpair>compair)
cout<<"User wins : "<<userpair<<" Pair";
else if(compair==userpair)
{
if(compaircard[0]>userpaircard[0])
cout<<"Computer wins : High pair";
else if(userpaircard[0]>compaircard[0])
cout<<"User wins : High pair";
else if(compaircard[0]==userpaircard[0] && compaircard[1]>userpaircard[1])
cout<<"Computer wins : Two High pair";
else if(userpaircard[0]==compaircard[0] && userpaircard[1]>compaircard[1])
cout<<"User wins : Two High pair";
else
highest();
}
}
else
highest();
}
void highest()
{
int user[2],com[2],i,highcount=0,temp;
for(i=0;i<2;i++)
{
com[i]=card[i];
user[i]=card[i+2];
}
if(user[0]>user[1])
{
temp=user[0];
user[0]=user[1];
user[1]=temp;
}
if(com[0]>com[1])
{
temp=com[1];
com[1]=com[0];
com[0]=temp;
}
for(i=2;i<7;i++)
{
if(comcard[i]!=usercard[i])
{
highcount++;
}
}
if(highcount>0)
{
if(com[1]>user[1])
cout<<"Computer wins : High card";
else if(user[1]>com[1])
cout<<"User wins : High card";
else if(com[0]>user[0])
cout<<"Computer wins : High card";
else if(user[0]>com[0])
cout<<"User wins : High card";
}
else 
cout<<"Draw : High Card";
}
This article has been dead for over six months. Start a new discussion instead.