Computers and Technology

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.

answer
Answers: 1

Other questions on the subject: Computers and Technology

image
Computers and Technology, 22.06.2019 23:30, keviongardner
The next button in the review section shows the next available comment. next slide with no comment. previous comment. edited comment.
Answers: 1
image
Computers and Technology, 23.06.2019 09:00, Riddledjam44623
Before you record your own voice, you should a. record other people's voices b. warm up and practice difficult names c. listen to your favorite songs d. read a transcript of a good radio news segment
Answers: 1
image
Computers and Technology, 23.06.2019 15:00, herchellann302
To check whether your writing is clear , you can
Answers: 2
image
Computers and Technology, 23.06.2019 21:40, jeovontamarley
language consists of basic components, and they are called a. 3; mental images, concepts, and speech b. 2; language acquisition and linguistic relativity c. 3; heuristics, algorithms, and analogies d. 4; phonemes, morphemes, syntax, and semantics e. 2; words and grammar
Answers: 3
Do you know the correct 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
History, 16.12.2021 03:40
Konu
Chemistry, 16.12.2021 03:40
Konu
English, 16.12.2021 03:40