Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
struct card {
const char *face;
const char *suit;
const char *color;
};
typedef struct card Card;
typedef unsigned char pairs;
void fillDeck( Card * const, const char *[], const char *[] ,const char *[]);
void shuffle( Card * const );
void print( const Card * const );
pairs findpairs(card *hand); /* finds any pairs in a hand */
int main()
{
int hand,cd,winner;
card hands[5][5],handssorted[5][5];
pairs numpairs[5],highest;
Card deck[52];
const char *face[] = { "Ace", "Two", "Three", "Four", "Five","Six", "Seven",
"Eight", "Nine", "Ten","Jack", "Queen", "King"};
const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"};
const char *color[]= {"Black","Red"};
srand( time( NULL ) );
fillDeck( deck, face, suit, color );
print( deck );
printf("\n ----------------------------------------------------------\n");
shuffle( deck );
print( deck );
int i=0;
for(cd=0;cd<5;cd++)
{
for(hand=0;hand<5;hand++)
{
hands[hand][cd]=deck[i];
i++;
/* deal the hands here */
}
}
for(hand=0;hand<5;hand++)
{
/* sort the hands here */
//qsort(hands[hand],5,sizeof(card),compareface());
numpairs[hand]=findpairs(handssorted[hand]);
printf("Hand %i:\n",hand+1);
/* print the hands here */
/* print the number and value of any pairs here */
}
/* determine the winner and print it */
system("pause");
return 0;
}
//------------------------------------------------------------------------------------------------------
void fillDeck( Card * const wDeck, const char * wFace[], const char * wSuit[], const char * wColor[])
{
int i;
for ( i = 0; i <= 51; i++ ) {
wDeck[i].face = wFace[ i % 13 ];
wDeck[i].suit = wSuit[ i / 13 ];
wDeck[i].color = wColor[i%2];
// if ()
// wDeck[i].suit = wSuit[ i / 13 ];
}
}
//-----------------------------------------------------------------------------------------------------
void shuffle( Card * const wDeck )
{
int i, j;
Card temp;
for ( i = 0; i <= 51; i++ ) {
j = rand() % 52;
temp = wDeck[ i ];
wDeck[ i ] = wDeck[ j ];
wDeck[ j ] = temp;
}
}
//-----------------------------------------------------------------------------------------------------------
void print( const Card * const wDeck )
{
int i;
for ( i = 0; i <= 51; i++ ){
printf( "\t%s\t of \t%-8s is \t%s \n \t", wDeck[i].face,
wDeck[i].suit,wDeck[i].color,
( i + 1 ) % 2 ? '\t' : '\n' );}
}
//------------------------------------------------------------------------------------------------------------
pairs findpairs(card *hand)
{
pairs numpairs=0;
for ( int i = 0; i <= 5; i++ ){
//if (hand[i].face == )
}
return numpairs;
}
//-----------------------------------------------------------------------------
int compareface(const void* c1, const void *c2)
{
/* This function extracts the two cards face values
and returns 1 if cd1 > cd2, 0 if cd1 == cd2, and
-1 otherwise. The weird argument types are for
compatibility with qsort(), the first two lines
decode the arguments back into "card".
*/
card cd1,cd2;
cd1=*((card*) c1);
cd2=*((card*) c2);
//cd1= (cd1&0x3c)>>2;
//cd2= (cd2&0x3c)>>2;
//if(cd1>cd2)
//return 1;
//if(cd1==cd2)
//return 0;
//return -1;
}