Question: Write a program in c that simulates a random hand of poker. A hand in poker is represented by 5 cards. A card is represented

Write a program in c that simulates a random hand of poker. A hand in poker is represented by 5 cards. A card is represented as a suit and a rank.

The rank is an integer between 1 and 13, inclusive. A 1 represents an Ace, an 11 represents a Jack, a 12 Queen, a 13 King.

A suit is one of Diamonds, Clubs, Hearts, or Spades.

typedef enum suit_s {DIAMONDS, CLUBS, HEARTS, SPADES} Suit;

typedef struct card_s { int rank; Suit suit; } Card;

Then develop functions to: create a random card, print a card, and destroy (deallocate) a card. Look up the rand() function for getting random numbers. Also create a function to determine whether two cards are equal.

A hand consists of five *distinct* cards. Create a structure to represent a hand, and functions to create a random hand, print a hand, and destroy deallocate) a hand. Re-use the functions for cards.

Write a function to determine whether a hand is a straight flush. A hand is a straight flush if both of the following are satisfied: (1) all 5 cards of the hand have the same suit, and (2) the ranks of the cards form a sequence of consecutive integers. However, for (2), the Ace (1) can count as EITHER 1 (the lowest rank), or as "14" (the highest rank), but NOT BOTH. For example, 1,2,3,4,5 is fine, as is 10,11,12,13,1. But not 11,12,13,1,2.

Create functions to test all of the above.

Finally, for your main function: take one command line input, the number of trials. Then iterate #trials times. At each iteration, generate a random hand, determine if it is a straight flush, increment a counter if so, and destroy the hand. At the end print out the number of trials, the total number of straight flushes encountered, and the fraction (a number between 0 and 1) of the hands that were straight flushes.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!