Tuesday, 10 January 2012

Simple Poker Game in C

#include
#include
#include
#include
/*#define SATIR 4
#define SUTUN 13*/
void desteyikar(int[][13]);
void desteyidagit(int[][13],const char*[],const char*[]);
void durum(int[][13],const char*[],const char*[]);
//int yeniden(void);

//void renk(char*[],char*[]);
int main()
{
    int again;
    const char*takim[4]={"kupa","karo","sinek","maca"};
    const char*taraf[13]={"as","iki","uc","dOrt","bes","alti","yedi","sekiz","dokuz","on","vale","kiz","papaz"};
      int deste[4][13]={0};
      char secim;
      
      
    
  
   printf("Poker oynamak ister misin E/H ? ");
 scanf("%c",&secim);
   if(secim!='h')
   {
   srand(time(0));
   desteyikar(deste);
  
   desteyidagit(deste,taraf,takim);
 
   durum(deste,taraf,takim);
  /*printf("Tekrar oynamak ister misin ? E/H");
  scanf("%c",&secim);*/
}

    getch();
    
    return 0;
       
}
void desteyikar(int adeste[][13])
{
    int satir,sutun,kart;

    for(kart=1;kart<=52;kart++)
    {
    do{
    satir=rand()%4;
    sutun=rand()%13;
    }while(adeste[satir][sutun]!=0);
    
    adeste[satir][sutun]=kart;
    }
}

void desteyidagit(int adeste[][13],const char*ataraf[],const char*atakim[])
{    
     
    
     int kart,satir,sutun;
     printf("Your hand is \n\n");
     for(kart=1;kart<=5;kart++)
     for(satir=0;satir<=3;satir++)
     for(sutun=0;sutun<=12;sutun++)
  
     if(adeste[satir][sutun]==kart)
     { 
     printf("%5s %-8s\t",atakim[satir],ataraf[sutun]);
     }
     printf("\nMy hand is \n\n");
     for(kart=6;kart<=10;kart++)
     for(satir=0;satir<=3;satir++)
     for(sutun=0;sutun<=12;sutun++)
  
     if(adeste[satir][sutun]==kart)
     { 
     printf("%5s %-8s\t",atakim[satir],ataraf[sutun]);
     }

}

void durum(int adeste[][13],const char*ataraf[],const char*atakim[])
{ 
      int kart,satir,sutun,r=0,q=0;
      char s1[5],s2[5],s3[5],s4[5],s5[5],s6[5],s7[5],s8[5],s9[5],s10[5];
      int buyukluk[10],i;
     for(kart=1;kart<=10;kart++)
     for(satir=0;satir<=3;satir++)
     for(sutun=1;sutun<=12;sutun++)
    { 
     if(adeste[satir][sutun]==1)
     { 
      
         
     *s1=*ataraf[sutun];
     *(s1+1)=*(ataraf[sutun]+1);
 *(s1+2)=*(ataraf[sutun]+2);
 *(s1+3)=*(ataraf[sutun]+3);
 *(s1+4)=*(ataraf[sutun]+4);                           
     }
     if(adeste[satir][sutun]==2)
     {  
    
     *s2=*ataraf[sutun];
     *(s2+1)=*(ataraf[sutun]+1);
 *(s2+2)=*(ataraf[sutun]+2);
 *(s2+3)=*(ataraf[sutun]+3);
 *(s2+4)=*(ataraf[sutun]+4);                      
    
     }
     if(adeste[satir][sutun]==3)
     { 
   *s3=*ataraf[sutun];
     *(s3+1)=*(ataraf[sutun]+1);
 *(s3+2)=*(ataraf[sutun]+2);
 *(s3+3)=*(ataraf[sutun]+3);
 *(s3+4)=*(ataraf[sutun]+4);
   
     }
     if(adeste[satir][sutun]==4)
     { 
   *s4=*ataraf[sutun];
     *(s4+1)=*(ataraf[sutun]+1);
 *(s4+2)=*(ataraf[sutun]+2);
 *(s4+3)=*(ataraf[sutun]+3);
 *(s4+4)=*(ataraf[sutun]+4);
  
     }
     if(adeste[satir][sutun]==5)
     { 
   *s5=*ataraf[sutun];
     *(s5+1)=*(ataraf[sutun]+1);
 *(s5+2)=*(ataraf[sutun]+2);
 *(s5+3)=*(ataraf[sutun]+3);
 *(s5+4)=*(ataraf[sutun]+4);
     }
     if(adeste[satir][sutun]==6)
     {
  for(i=0;i<=4;i++)
  *(s6+i)=*(ataraf[sutun]+i);       
     }
     if(adeste[satir][sutun]==7)
     {
  for(i=0;i<=4;i++)
  *(s7+i)=*(ataraf[sutun]+i);       
     }
     if(adeste[satir][sutun]==8)
     {
  for(i=0;i<=4;i++)
  *(s8+i)=*(ataraf[sutun]+i);       
     }
     if(adeste[satir][sutun]==9)
     {
  for(i=0;i<=4;i++)
  *(s9+i)=*(ataraf[sutun]+i);       
     }
     if(adeste[satir][sutun]==10)
     {
  for(i=0;i<=4;i++)
  *(s10+i)=*(ataraf[sutun]+i);       
     }
    }

    buyukluk[0]=sizeof(s1)/sizeof(char);
    buyukluk[1]=sizeof(s2)/sizeof(char);
    buyukluk[2]=sizeof(s3)/sizeof(char);
    buyukluk[3]=sizeof(s4)/sizeof(char);
    buyukluk[4]=sizeof(s5)/sizeof(char);
    buyukluk[5]=sizeof(s6)/sizeof(char);
    buyukluk[6]=sizeof(s7)/sizeof(char);
    buyukluk[7]=sizeof(s8)/sizeof(char);
    buyukluk[8]=sizeof(s9)/sizeof(char);
    buyukluk[9]=sizeof(s10)/sizeof(char);
    

    if(buyukluk[0]==buyukluk[1])
      if((*s1==*s2)&&(*(s1+1)==*(s2+1)))
  r++;
 if(buyukluk[0]==buyukluk[2])
      if((*s1==*s3)&&(*(s1+1)==*(s3+1)))
  r++;
     if(buyukluk[0]==buyukluk[3])
      if((*s1==*s4)&&(*(s1+1)==*(s4+1)))
  r++;
     if(buyukluk[0]==buyukluk[4])
      if((*s1==*s5)&&(*(s1+1)==*(s5+1)))
  r++;
     if(buyukluk[1]==buyukluk[2])
      if((*s2==*s3)&&(*(s2+1)==*(s3+1)))
  r++;
     if(buyukluk[1]==buyukluk[3])
      if((*s2==*s4)&&(*(s2+1)==*(s4+1)))
  r++;  
  if(buyukluk[1]==buyukluk[4])
      if((*s2==*s5)&&(*(s2+1)==*(s5+1)))
  r++;
 if(buyukluk[2]==buyukluk[3])
      if((*s3==*s4)&&(*(s3+1)==*(s4+1)))
  r++;
     if(buyukluk[2]==buyukluk[3])
      if((*s3==*s5)&&(*(s3+1)==*(s5+1)))
  r++;
     if(buyukluk[3]==buyukluk[4])
      if((*s4==*s5)&&(*(s4+1)==*(s5+1)))
  r++;
     
    if(buyukluk[5]==buyukluk[6])
      if((*s5==*s6)&&(*(s5+1)==*(s6+1)))
  q++;
 if(buyukluk[5]==buyukluk[7])
      if((*s5==*s7)&&(*(s5+1)==*(s7+1)))
  q++;
     if(buyukluk[5]==buyukluk[8])
      if((*s5==*s8)&&(*(s5+1)==*(s8+1)))
  q++;
     if(buyukluk[5]==buyukluk[9])
      if((*s5==*s9)&&(*(s5+1)==*(s9+1)))
  q++;
     if(buyukluk[6]==buyukluk[7])
      if((*s6==*s7)&&(*(s6+1)==*(s7+1)))
  q++;
     if(buyukluk[6]==buyukluk[8])
      if((*s6==*s8)&&(*(s6+1)==*(s8+1)))
  q++;  
  if(buyukluk[6]==buyukluk[9])
      if((*s6==*s9)&&(*(s6+1)==*(s9+1)))
  q++;
 if(buyukluk[7]==buyukluk[8])
      if((*s7==*s8)&&(*(s7+1)==*(s8+1)))
  q++;
     if(buyukluk[7]==buyukluk[9])
      if((*s7==*s9)&&(*(s7+1)==*(s9+1)))
  q++;
     if(buyukluk[8]==buyukluk[9])
      if((*s8==*s9)&&(*(s8+1)==*(s9+1)))
  q++;
    
     
    if(r==1)
    printf("\nYour hand has One pair\n");
    if(r==2)
    printf("\nYour hand has Two pair\n"); 
    if(r==3)
    printf("\nYour hand has Three of a Kind\n");
    if(r==6)
    printf("\nYour hand has Four of a Kind\n");
    printf("\n\n");

    if(q==1)
    printf("\nMy hand has One pair\n");
    if(q==2)
    printf("\nMy hand has Two pair\n"); 
    if(q==3)
    printf("\nMy hand has Three of a Kind\n");
    if(q==6)
    printf("\nMy hand has Four of a Kind\n");
    printf("\n-------------------------------------------\n");
    if(r>q)
    printf("Your hand is winner\n");
    if(q>r)
    printf("My hand is winner\n");
    if(q==r)
    printf("Draw\n");
}
  


1 comment: