Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hw need help! This is for C programming :D You are tired of programming, so you

ID: 3757975 • Letter: H

Question

Hw need help! This is for C programming :D

You are tired of programming, so you decide to play nickel, dime, quarter poker on Friday night with some custom house rules:

Little Dog: Seven high, two low (for example, 7-6-4-3-2). It ranks just above a straight, and below a flush or any other cat or dog.

Big Dog: Ace high, nine low (for example, A-K-J-10-9). It ranks above a straight, or little dog, and below a flush or cat.

Little Cat: Eight high, three low. It ranks above a straight or any dog, but below a flush or big cat.

Big Cat: King high, eight low. It ranks just below a flush, and above a straight or any other cat or dog.

Royal Flush: The highest straight flush, A-K-Q-J-10, all of the same suit.

The following links may be helpful if you are a bit unfamiliar with poker rules:

http://en.wikipedia.org/wiki/List_of_poker_hands http://en.wikipedia.org/wiki/Non_standard_poker_hands

Unfortunately, you are so tired, that you have trouble figuring out what hand you have, so you decide to write a program to help you. Back to programming!

Specifications:

Use the poker.c source code provided by K. N. King as an initial code base. Modify the code to allow for the custom house rules listed above, and to allow the user to play either 5 card stud (normal poker) or 7 card stud. See the rules for 7 card stud if you are unfamiliar with them:

http://en.wikipedia.org/wiki/Seven-card_stud

In 7 card stud, you play the best 5 of 7 poker cards. Therefore, if the user chooses to play 7 card stud, you will have to allow 7 cards to be input into the system. You will then use the 2d card_exists[][] array and the 1D num_in_rank[] array to figure out the best hand. The output should then display the best hand and print out the 5 cards being used to create it.

For example: Alice shows her cards: 9 5 9 K K 3 5. The best five-card poker hand she can play is K-K-9-9-5, making two pair, kings and nines. Carol shows Q 2 K J 10 10 A. She can play A-K-Q-J-10, making an ace-high straight, and so Carol wins the pot.

If you execute the program, the following information should be displayed:

~> hw24.o Welcome to Poker Press 0 to Quit

5 Card or 7 Card Stud? (Type 5 or 7): 0

~> hw24.o Welcome to Poker Press 0 to Quit

5 Card or 7 Card Stud? (Type 5 or 7): 5 5 Card Stud will be played.

Enter a card: 0

~> hw24.o Welcome to Poker Press 0 to Quit

5 Card or 7 Card Stud? (Type 5 or 7): 5 5 Card Stud will be played.

Enter a card: 9k
Bad card; ignored.
Enter a card: kh
Enter a card: kh Duplicate card; ignored. Enter a card: qc

Enter a card: ts Enter a card: 9s Enter a card: 8h

Big Cat

5 Card or 7 Card Stud? (Type 5 or 7): 7 7 Card Stud will be played.

Enter a card: kh Enter a card: kc Enter a card: kd Enter a card: qc Enter a card: ts Enter a card: 9s Enter a card: 7h

5 Card or 7 Card Stud? (Type 5 or 7: 0 ~>

Explanation / Answer

#include <stdbool.h>   
#include <stdio.h>
#include <stdlib.h>
#define NUM_RANKS 13
#define NUM_SUITS 4
#define NUM_CARDS 5
int num_in_rank[NUM_RANKS];
int num_in_suit[NUM_SUITS];
bool straight, flush, four, three;
int pairs;
bool card_exists[NUM_RANKS][NUM_SUITS];
char ch, rank_ch, suit_ch;
int rank, suit;
bool bad_card;
int cards_read = 0;
for (rank = 0; rank < NUM_RANKS; rank++)
{
num_in_rank[rank] = 0;
for (suit = 0; suit < NUM_SUITS; suit++)
card_exists[rank][suit] = false;
}
for (suit = 0; suit < NUM_SUITS; suit++)
num_in_suit[suit] = 0;
while (cards_read < NUM_CARDS)
{
bad_card = false;
printf("Enter a card: ");
rank_ch = getchar();
switch (rank_ch)
{
case '0': exit(EXIT_SUCCESS);
case '2': rank = 0; break;
case '3': rank = 1; break;
case '4': rank = 2; break;
case '5': rank = 3; break;
case '6': rank = 4; break;
case '7': rank = 5; break;
case '8': rank = 6; break;
case '9': rank = 7; break;
case 't': case 'T': rank = 8; break;
case 'j': case 'J': rank = 9; break;
case 'q': case 'Q': rank = 10; break;
case 'k': case 'K': rank = 11; break;
case 'a': case 'A': rank = 12; break;
default: bad_card = true;
}
switch (suit_ch)
{
case 'c': case 'C': suit = 0; break;
case 'd': case 'D': suit = 1; break;
case 'h': case 'H': suit = 2; break;
case 's': case 'S': suit = 3; break;
default: bad_card = true;
}
while ((ch = getchar()) != ' ')
if (ch != ' ') bad_card = true;
if (bad_card)
printf("Bad card; ignored. ");
printf("Duplicate card; ignored. ");*/
else
{
num_in_rank[rank]++;
num_in_suit[suit]++;
card_exists[rank][suit] = true;
cards_read++;
}
}
{
int num_consec = 0;
bool straights = false;
flush = false;
four = false;
three = false;
pairs = 0;
rank = 0;
while (num_in_rank[rank] == 0) rank++;
for (; rank < NUM_RANKS && num_in_rank[rank] > 0; rank++)
num_consec++;
if (num_consec == NUM_CARDS)
{
straight = true;
}
for (rank = 0; rank < NUM_RANKS; rank++)
{
if (num_in_rank[rank] == 4) four = true;
if (num_in_rank[rank] == 3) three = true;
if (num_in_rank[rank] == 2) pairs++;
}
}
if (four)printf("Four of a kind");
else if (three &&pairs == 1) printf("Full house");
else if (flush) printf("Flush");
else if (straight) printf("Straight");
else if (three) printf("Three of a kind");
else if (pairs == 2) printf("Two pairs");
else if (pairs == 1) printf("Pair");
else printf("High card");
getch();
printf(" ");
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote