Boolean check_four_kind (const int wDeck[][13], const char *wFace[], const char *wSuit[], Card card[5], Boolean display_hand_info)
{
Boolean four_kind_exist = FALSE;
int h = 0, n = 0, r = 0, q = 0; //variables used for iterating through the subvalues (cards) of the card[] array
//function test case
//card[0].face = 1;
//card[1].face = 0;
//card[2].face = 1;
//card[3].face = 1;
//card[4].face = 1;
//iterates through cards in the card struct and compares them to every other card in the hand.
while (h < 5) //tier1: loop cards
{
while (n < 5) //tier2: loop every card in the hand and compare to the card specified by 'h'
{
if (card[h].face == card[n].face && h != n) //if n != h, then the card in the struct is different than the one it is being compared to.
{
/*printf ("card[%d]=card[%d] ", h, n);*/
while (r < 5) //tier3: loop every card in the hand and compare to the card specified by 'n'
{
if (card[n].face == card[r].face && r != n && r != h) //if r != (n or h), then it is a unique value
{
while (q < 5) //tier4: loop every card in the hand and compare to the card specified by 'r'
{
if (card[r].face == card[q].face && q != r && q != n && q != h)
four_kind_exist = TRUE;
q++; //increment q so a different card can be selected
}
}
q = 0; //reset variable so it can be used again
r++; //increment r so a different card can be selected
}
}
r = 0; //reset variable so it can be used again
n++; //increment n so a different card can be selected
}
n = 0; //reset variable so it can be used again
h++; //increment h so a different card can be selected
}
if (display_hand_info == TRUE) //displays info if it is warranted (aka, it keeps from needlessly displaying the hand info of the computer).
{
if (four_kind_exist == TRUE)
printf ("This hand contains Four of a Kind.\n");
else
printf ("This hand does not contain Four of a Kind.\n");
}
return four_kind_exist;
}