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. Create an enumeration for suit and call the resulting type Suit:
typedef enum suit_s {DIAMONDS, CLUBS, HEARTS, SPADES} Suit;
Create a structure to represent a card. It should look something like this:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started