Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PLEASE ANSWER QUESTION 7.15 USING C PROGRAMING I have attached all the information needed. The code to figure 7.24 is: #include #include #include #define SUITS

PLEASE ANSWER QUESTION 7.15 USING C PROGRAMING

I have attached all the information needed.

image text in transcribed

The code to figure 7.24 is:

#include

#include

#include

#define SUITS 4

#define FACES 13

#define CARDS 52

//prototypes

void shuffle(unsigned int wDeck[][FACES]); //shufling modifies wDeck

void deal(unsigned int wDeck[][FACES], const char *wFace[], const char *wSuit[]); //dealing doesn't modify arrays

int main()

{

//initialize suit array

const char *suit[SUITS] = {"Hearts", "Diamonds", "Clubs", "Spades"};

//initialize face array

const char *face[FACES] = {"Ace", "Deuce", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};

//initialize deck array

unsigned int deck[SUITS][FACES] = {0};

srand(time(NULL)); //seed random-number generator

shuffle(deck);

deal(deck, face, suit);

}

void shuffle(unsigned int wDeck[][FACES])

{

size_t row; //row #

size_t column; //column #

size_t card; //counter

//for each of the cards, choose slot of deck randomly

for (card = 1; card

{

//choose new random location until unoccupied slot found

do

{

row = rand() % SUITS;

column = rand() % FACES;

} while(wDeck[row][column] != 0);

//place card # in chosen slot of deck

wDeck[row][column] = card;

}

}

//deal cards in deck

void deal(unsigned int wDeck[][FACES], const char *wFace[], const char *wSuit[])

{

size_t card; //card counter

size_t row; //row counter

size_t column; //column counter

//deal each of the cards

for(card = 1; card

{

for(row = 0; row

{

for(column = 0; column

{

//if slot contains current card, display card

if (wDeck[row][column] == card)

{

printf("%5s of %-8s ", wFace[column], wSuit[row], card % 2 == 0 ? ' ' : '\t');

}

}

}

}

}

7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: Exercises 297 a) b) c) d) e) f) Determine if the hand contains a pair Determine if the hand contains two pairs. Determine if the hand contains three of a kind (e.g., three jacks) Determine if the hand contains four of a kind (e.g., four aces) Determine if the hand contains a flush (i.e., all five cards of the same suit) Determine if the hand contains a straight (i.e., five cards of consecutive face values) 7.13 (Project: Card Shuffling and Dealing) Use the functions developed in Exercise 7.12 to write a program that deals two five-card poker hands, evaluates each hand, and determines which is the better hand. 7.14 (Project: Card Shuffling and Dealing) Modify the program developed in Exercise 7.13 so that it can simulate the dealer. The dealer's five-card hand is dealt "face down" so the player cannot see it. The program should then evaluate the dealer's hand, and based on the quality of the hand, the dealer should draw one, two or three more cards to replace the corresponding number of un- needed cards in the original hand. The program should then re-evaluate the dealer's hand. [Caution: This is a difficult problem!] 7.15 (Project: Card Shuffling and Dealing) Modify the program developed in Exercise 7.14 so that it can handle the dealer's hand automatically, but the player is allowed to decide which cards of the player's hand to replace. The program should then evaluate both hands and determine who wins. Now use this new program to play 20 games against the computer you or the computer? Have one of your friends play 20 games against the computer. Who wins more games? Based on the results of these games, make appropriate modifications to refine your poker playing program (this, too, is a difficult problem). Play 20 more games. Does your modified pro- gram play a better game? Who wins more games, 7.12 (Card Shuffling and Dealing) Modify the program in Fig. 7.24 so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: Exercises 297 a) b) c) d) e) f) Determine if the hand contains a pair Determine if the hand contains two pairs. Determine if the hand contains three of a kind (e.g., three jacks) Determine if the hand contains four of a kind (e.g., four aces) Determine if the hand contains a flush (i.e., all five cards of the same suit) Determine if the hand contains a straight (i.e., five cards of consecutive face values) 7.13 (Project: Card Shuffling and Dealing) Use the functions developed in Exercise 7.12 to write a program that deals two five-card poker hands, evaluates each hand, and determines which is the better hand. 7.14 (Project: Card Shuffling and Dealing) Modify the program developed in Exercise 7.13 so that it can simulate the dealer. The dealer's five-card hand is dealt "face down" so the player cannot see it. The program should then evaluate the dealer's hand, and based on the quality of the hand, the dealer should draw one, two or three more cards to replace the corresponding number of un- needed cards in the original hand. The program should then re-evaluate the dealer's hand. [Caution: This is a difficult problem!] 7.15 (Project: Card Shuffling and Dealing) Modify the program developed in Exercise 7.14 so that it can handle the dealer's hand automatically, but the player is allowed to decide which cards of the player's hand to replace. The program should then evaluate both hands and determine who wins. Now use this new program to play 20 games against the computer you or the computer? Have one of your friends play 20 games against the computer. Who wins more games? Based on the results of these games, make appropriate modifications to refine your poker playing program (this, too, is a difficult problem). Play 20 more games. Does your modified pro- gram play a better game? Who wins more games

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions