# Thread: Calculate the rank of poker game

1. ## Calculate the rank of poker game

i've been thinking this problem many time,but didn't know how to do this. Need Some Help!

The example are listed as follows

largest
Rank1 A A A A
Rank2 A A A
Rank3 A A + K K
Rank4 A A
Rank5 A

smallest
Rank1 2 2 2 2
Rank2 2 2 2
Rank3 2 2 + 3 3
Rank4 2 2
Rank5 2

i've completed to compile how to shuffle and deal the cards,
now is also owe this one, are there any helpers to help me?
Thanks a lot.

2. anyone can help me?

3. It's not totally clear what you want to do. If this is actually 4-card poker (you do know it is normally 5?), a straight or flush will beat three of a kind, and three 2's beat 2 pairs, even if the pairs are aces and kings. So you should compare on the basis of hands first:

Four card poker - Wikipedia, the free encyclopedia

Use a function that checks for each hand in order and returns an enum value, eg:

Code:
```enum {
NOTHING,
PAIR,
TWO_PAIR,
STRAIGHT,
[...etc]
};```
If there is a tie, then use the card values (eg, if both hands == NOTHING, you are looking for the "high card").

4. My code is posted as follows
Maybe now is clearly what i want to say
In my code,these 4players should be compared by the rank
Code:
```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define  ARY_SIZE  52

void bldPerm   (int randNos[]);
void printData (int data[], int size, int lineSize);

int main (void)
{

int randNos [ARY_SIZE];
int data;

do{
printf("Begin shuffing cards.\n");

bldPerm   (randNos);
printData (randNos, 21, 4 );

return 0;
}

void bldPerm (int randNos[])
{

int oneRandNo;
int haveRand[ARY_SIZE] = {0};
int i;
int total=0;

srand(time(NULL));

for (i = 1; i < ARY_SIZE; i++)
{
do
{
oneRandNo = (rand() % (ARY_SIZE-1) ) +1;
total++;
} while (haveRand[oneRandNo] == 1);

haveRand[oneRandNo] = 1;
randNos[i] = oneRandNo;

}
printf("%c : %c : %c :%c \n",6,3,5,4);
return;
}

void printData (int data[], int size, int lineSize)
{

int numPrinted = 0;
int i;
int pttn, card;
int sP1,sP2,sP3,sP4;

printf("\n");
for ( i = 1; i < lineSize+1; i++)
printf(" Player%d \t", i);
printf("\n");

for ( i = 1; i < lineSize+1; i++)
printf("=========\t");
printf("\n");

for ( i = 1; i < size; i++)
{
numPrinted++;
pttn = data[i]/13;
card = data[i]%13+1;

switch(card)
{
case 1:printf(" A of");
break;
case 11:printf(" J of");
break;
case 12:printf(" Q of");
break;
case 13:printf(" K of");
break;
default:printf("%2d of",card);
break;
}
switch(pttn)
{
case 0:printf(" %c\t\t",6);
break;
case 1:printf(" %c\t\t",3);
break;
case 2:printf(" %c\t\t",5);
break;
case 3:printf(" %c\t\t",4);
break;
}

if (numPrinted >= lineSize)
{
printf("\n");
numPrinted = 0;
}
}

/*;*/sP1=data[1]%13+1 + data[5]%13+1 + data[9]%13+1 + data[13]%13+1 + data[17]%13+1;
sP2=data[2]%13+1 + data[6]%13+1 + data[10]%13+1 + data[14]%13+1 + data[18]%13+1;
sP3=data[3]%13+1 + data[7]%13+1 + data[11]%13+1 + data[15]%13+1 + data[19]%13+1;
sP4=data[4]%13+1 + data[8]%13+1 + data[12]%13+1 + data[16]%13+1 + data[20]%13+1;

for ( i = 1; i < lineSize+1; i++)
printf("=========\t");
printf("\n");

int Sum[]={0,sP1,sP2,sP3,sP4};

for( i = 1; i < lineSize+1; i++)
{
printf("  T%d=%d  \t", i, Sum[i]);
}

if ((Sum[1] > Sum[2]) && (Sum[1] > Sum[3]) && (Sum[1] > Sum[4]))
printf("\n\nPlayer 1 has win.\n");
else if ((Sum[2] > Sum[1]) && (Sum[2] > Sum[3]) && (Sum[2] > Sum[4]))
printf("\n\nPlayer 2 has win.\n");

else if ((Sum[3] > Sum[1]) && (Sum[3] > Sum[2]) && (Sum[3] > Sum[4]))
printf("\n\nPlayer 3 has win.\n");

else if ((Sum[4] > Sum[1]) && (Sum[4] > Sum[2]) && (Sum[4] > Sum[3]))
printf("\n\nPlayer 4 has win.\n");

else if ((Sum[1] == Sum[2]) && (Sum[1]== Sum[3]) &&  (Sum[1]== Sum[4]))
printf("\n\nThe game is drawn.");
else if ((Sum[2] == Sum[1]) && (Sum[2]== Sum[3]) &&  (Sum[2]== Sum[4]))
printf("\n\nThe game is drawn.");
else if ((Sum[3] == Sum[1]) && (Sum[3]== Sum[2]) &&  (Sum[3]== Sum[4]))
printf("\n\nThe game is drawn.");
else if ((Sum[4] == Sum[1]) && (Sum[4]== Sum[2]) &&  (Sum[4]== Sum[3]))
printf("\n\nThe game is drawn.");

return ;
}```
i need your help,thanks a lot.