Sie sind auf Seite 1von 3

#include<stdio.

h>
#include<stdlib.h>
#include<time.h>
void shuffle(int wDeck[][13]);
void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[]);
char *handFace[10];
char *handSuit[10];
void paircheck(char *handP[]){
int i,j;
char *res=" ";
for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
if((i!=j)&&(handP[i]==handP[j])&&(handP[i]!=res)){
printf("A pair of %s\n",handP[i]);
res=handP[i];
break;
}
}
}
}
void pair2check(char *handP[]){
int i,j,t=0;
char *res1=" ";
char *res=" ";
for(i=1;i<=5;i++){
for(j=1;j<=5;j++){
if((i!=j)&&(handP[i]==handP[j])&&(handP[i]!=res)&&(t==0)){
//printf("A pair of %s ",handP[i]);
res=handP[i];
t=1;
break;
}
if((i!=j)&&(handP[i]==handP[j])&&(handP[i]!=res)&&(t==1)){
printf("A pair of %s ",res);
printf("and a pair of %s ",handP[i]);
res=handP[i];
t=1;
break;
}
}
}
}
void fourcheck(char *handP[]){
int f=0,i,j,c=0;
for(i=1;i<=5;i++){
c=0;
for(j=1;j<=5;j++){
if((handP[i]==handP[j])&&(i!=j)){
c++;
}
if(c==4){
printf(" Four %s\n",handP[i]);
f=1;
break;
}
}
if(f==1) break;
}
}
void threecheck(char *handP[]){
int f=0,i,j,c=0;
for(i=1;i<=5;i++){
c=0;
for(j=1;j<=5;j++){
if((handP[i]==handP[j])&&(i!=j)){
c++;
}
if(c==3){
printf(" Four %s\n",handP[i]);
f=1;
break;
}
}
if(f==1) break;
}
}
void flushcheck(char *suitP[]){
int f=0,i,j,c=0;
for(i=1;i<=5;i++){
c=0;
for(j=1;j<=5;j++){
if((suitP[i]==suitP[j])&&(i!=j)){
c++;
}
if(c==4){
printf(" Flush %s\n",suitP[i]);
f=1;
break;
}
}
if(f==1) break;
}
}

int main(void){
const char *suit[4]={"Hearts","Diamonds","Clubs","Spades"};
const char *face[13]={"Ace","Deuce","Three","Four","Five","Six","Seven","Eig
ht","Nine","Ten","Jack","Queen","King"};
int deck[4][13]={0};
srand(time(0));
shuffle(deck);
deal(deck,face,suit);
printf("\n");
int i;
/*for(i=1;i<=5;i++){
printf("%s %s\n",handFace[i],handSuit[i]);
}*/
paircheck(handFace);
pair2check(handFace);
fourcheck(handFace);
threecheck(handFace);
flushcheck(handSuit);

system("PAUSE");
return 0;
}
void shuffle(int wDeck[][13]){
int row;
int column;
int card;
for(card=1;card<=52;card++){
do{
row=rand()%4;
column=rand()%13;
// printf("Test\n");
}while(wDeck[row][column]!=0);
wDeck[row][column]=card;
}
}

void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[]){


int card;
int row;
int column;
for(card=1;card<=5;card++){
for(row=0;row<=3;row++){
for(column=0;column <=12;column++){
if(wDeck[row][column]==card){
printf("%5s of %-8s%c",wFace[column],wSuit[row],card%2==0 ? '\n': '\
t');
handFace[card]=wFace[column];
handSuit[card]=wSuit[row];
}
}
}
}
}
/*void deal(const int wDeck[][13],const char *wFace[],const char *wSuit[]){
int card;
int row;
int column;
for(card=1;card<=52;card++){
for(row=0;row<=3;row++){
for(column=0;column <=12;column++){
if(wDeck[row][column]==card){
printf("%5s of %-8s%c",wFace[column],wSuit[row],card%2==0 ? '\n': '\
t');
}
}
}
}
}*/