Question
Play Cards. Can someone help me modify this program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal
Play Cards.
Can someone help me modify this program to 'deal' two hands of cards (two players). Each player will be dealt 5 cards. Deal one to the first player, then one to second player. Repeat until both players have 5 cards in their hand.
Then compute the total points in each player's hand and determine the winner with the most points. If a player has an ace, then count that as 11 points.
Print out the winning player total points and then his cards.
Then print out the losing player total points and his cards.
This is C code.
#include
#define NCARDS 52 #define NPROPS 2
#define NSUITS 4 #define NFACES 13
char* suit[NSUITS]={"hearts","spades","clubs","diamonds"};
char* face[NFACES]={"ace","two","three","four","five","six","seven","eight","nine", "ten","jack","queen","king"};
void PrintCard(int deck[NCARDS][NPROPS], int i); void InitDeck(int deck[NCARDS][NPROPS]); void SwapCards(int deck[NCARDS][NPROPS], int src, int dest); void ShuffleDeck(int deck[NCARDS][NPROPS]); int GetPlayValue(int deck[NCARDS][NPROPS], int i);
int main() { int deck[NCARDS][NPROPS]; int src; int dest; int i; srand(time(NULL)); printf(" Initializing the deck... "); InitDeck(deck); printf(" Shuffling the deck... "); ShuffleDeck(deck);
for (i=0; i return 0; } void InitDeck(int deck[NCARDS][NPROPS]) { int suit; int face; int row = 0; for (suit=0; suit<4; suit++) for (face=0; face<13; face++) { deck[row][0]= suit; deck[row][1]= face; row++; } } void ShuffleDeck(int deck[NCARDS][NPROPS]) { int src, dest, i; for (i=0; i void SwapCards(int deck[NCARDS][NPROPS], int src, int dest) { int temp; temp = deck[src][0]; deck[src][0] = deck[dest][0]; deck[dest][0] = temp; temp = deck[src][1]; deck[src][1] = deck[dest][1]; deck[dest][1] = temp; } void PrintCard(int deck[NCARDS][NPROPS], int i) { int tempsuit; int tempface; tempsuit = deck[i][0]; tempface = deck[i][0]; printf(" Card %d = %s of %s - Value = %d", i+1, face[tempface], suit[tempsuit], GetPlayValue(deck,i)); } int GetPlayValue(int deck[NCARDS][NPROPS], int i) { int suit = deck[i][0]; int face = deck[i][0]; int value; if(face ==0) return 1; else if( (face > 0) && (face < 10)) return face+1; else return 10; }
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