subject

In this assignment we will work on the creation of a poker game. at a minimum your game must deal 2 hands of cards, and print out what poker hand each has. it must also determine which hand has won the game – but breaking a tie will be for bonus points. for example, if both hands have 3 of a kind, that can be considered a tie. if you want the bonus points write some code that determines which 3 of a kind is higher.

here is the output from dealing a hand of cards:

ace of hearts
ten of clubs
ace of clubs
eight of hearts
seven of diamonds

2 2 1 0 < > 0 0 0 0 0 1 1 0 1 0 0 0 2

you have a pair!

use lots of small functions to reduce the complexity of the code.
you must use the code from the video to get started, and you must use the following representation for a poker hand:
make 2 arrays: suitsinhand[4], and facesinhand[14].
suitsinhand is 4 counters that represents how many hearts, clubs, diamonds, spades are in the hand. these 4 counters must add up to 5 for a hand of 5 cards. for example if you have 5 hearts in the hand of cards, the array would have the values 5,0,0,0
facesinhand is 13 counters, that represent how many two’s, three’s, etc. you have in the hand. this must also total 5. for example, if you have a pair of 3’s, and three kings’s, this array would have the values 0,2,0,0,0,0,0,0,0,0,3,0

while dealing a hand of cards, keep a count of the suitsinhand, and facesinhand.

i will include some code below that will you to figure out what poker hand you have dealt.
this function will use the 2 arrays described above to determine if the hand has a flush, straight, etc. i have not included the parameters. you will need to pass in the hand of cards, and have the function pass back if there is a flush, straight, three of a kind, etc.

/* analyzehand: determines whether the hand contains a straight, a flush, four-of-a-kind, and/or a three-of-a-kind; determines the number of pairs; stores the results into the external variables straight, flush, four, three, and pairs. */

void analyzehand( …
{ int num_consec = 0;
int rank, suit;
straight = false;
flush = false;
four = false;
three = false;
pairs = 0;

// check for flush – 5 cards of the same suit

for (suit = 0; suit < suits; suit++)

if (suitsinhand[suit] == 5)

flush = true;

// check for straight – eg. one each of 5,6,7,8,9

// locate the first card rank = 0;

while (facesinhand[rank] == 0)

rank++;

// count the consecutive non-zero faces

for (; rank < faces & & facesinhand[rank]; rank++)

num_consec++;

if (num_consec == 5) {

straight = true;

return;

}

/* check for 4-of-a-kind, 3-of-a-kind, and pairs */

for (rank = 0; rank < num_ranks; rank++) {

if (facesinhand[rank] == 4)

four = true;

if (facesinhand[rank] == 3)

three = true;

if (facesinhand[rank] == 2)

pairs++;

}

}

here is a block of code that might you determine what hand is better than another. these are in order. a straight-flush is the best hand, and a high-card is the worst hand.

if (straight & & flush)
printf("straight flush\n\n");
else if (four)
printf("four of a kind\n\n");
else if (three & & pairs == 1)
printf("full house\n\n");
else if (flush)
printf("flush\n\n");
else if (straight)
printf("straight\n\n");
else if (three)
printf("three of a kind\n\n");
else if (pairs == 2)
printf("two pairs\n\n");
else if (pairs == 1)
printf("pair\n\n");
else printf("high card\n\n");
deliverables: 1. paste your code below, in this document.

2. include the output of running the program 10 times. include several different cases, for example 2 pair, high card. each case that you expect points for will be demonstrated in the output.

ansver
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 21.06.2019 22:00, suyi14
What operating system is a smartphone most likely to use? 1.bsd 2.mac os x 3.symbian 4.linux
Answers: 1
image
Computers and Technology, 22.06.2019 13:00, mariahrpoulin9630
Which part of the cpu accepts data?
Answers: 1
image
Computers and Technology, 22.06.2019 19:30, tfaulk2884
Singing in the rain: this first part of the film shows the early history of motion picture. how accurate do you think the portrayal of the early motion picture industry is? why? is historical accuracy important in films and theater productions? explain.
Answers: 1
image
Computers and Technology, 23.06.2019 21:40, minnie7760
Draw the resistor’s voltage and current phasors at t=15ms. draw the vectors with their tails at the origin. the orientation of your vectors will be graded. the exact length of your vectors will not be graded.
Answers: 2
You know the right answer?
In this assignment we will work on the creation of a poker game. at a minimum your game must deal 2...

Questions in other subjects:

Konu
English, 18.09.2021 19:40
Konu
Mathematics, 18.09.2021 19:40