C Programming Absolute Beginner's Guide (3rd Edition)

(Romina) #1

} while ((bet < 0) || (bet > 5));
}


// Last function reviews the final hand and determines the value of
// the hand.


int analyzeHand(int ranksinHand[], int suitsinHand[])
{
int num_consec = 0;
int i, rank, suit;
int straight = FALSE;
int flush = FALSE;
int four = FALSE;
int three = FALSE;
int pairs = 0;


for (suit = 0; suit < 4; suit++)
if (suitsinHand[suit] == 5)
flush = TRUE;
rank = 0;
while (ranksinHand[rank] == 0)
rank++;
for (; rank < 13 && ranksinHand[rank]; rank++)
num_consec++;
if (num_consec == 5) {
straight = TRUE;
}
for (rank = 0; rank < 13; rank++) {
if (ranksinHand[rank] == 4)
four = TRUE;
if (ranksinHand[rank] == 3)
three = TRUE;
if (ranksinHand[rank] == 2)
pairs++;
}


if (straight && flush) {
printf("Straight flush\n\n");
return (20);
}
else if (four) {
printf("Four of a kind\n\n");
return (10);
}
else if (three && pairs == 1) {
printf("Full house\n\n");
return (8);
}
else if (flush) {
printf("Flush\n\n");
return (5);
}
else if (straight) {
printf("Straight\n\n");
return (4);
}
else if (three) {

Free download pdf