# Flush, Straight, and Straight Flush Tests (Poker VI)

After pulling out any hands arranged in a straight pattern, covered in last week’s Lesson, the next logical test is for a flush. The flush draw is when all cards are of the same suit.

Here is the flush() function I wrote to determine when cards in the hand represented by the playing_card structure p are arranged as a flush draw:

/* Determine a flush draw */
int flush(struct playing_card p[])
{
wchar_t s;
int x;

/* obtain the first card's suit */
s = p[0].suit;
/* compare with all the other cards */
for( x=1; x<HAND_SIZE; x++ )
{
if( s != p[x].suit )
return(FALSE);
}

return(TRUE);
}

After the first card’s suit is obtained (p[0].suit), its value is compared with the remaining four cards in the hand. If any other card doesn’t match, FALSE is returned. If the code survives the for loop, TRUE is returned.

To test the hand drawn, the main() function offers a series of if tests. The first is for the straight flush test:

if( straight(hand[x]) && flush(hand[x]) )
{
wprintf(L" - Straight Flush\n");
x++;
continue;
}

If the hand returns TRUE for both the straight() and flush() functions, the result is a straight flush. Text is output, the looping variable x is incremented, and the continue statement skips the remaining tests, looping another time.

The next test is for a straight:

if( straight(hand[x]) )
{
wprintf(L" - Straight\n");
x++;
continue;
}

Then comes the flush test:

if( flush(hand[x]) )
{
wprintf(L" - Flush\n");
x++;
continue;
}