Question
[IN C CODE PLEASE] #include #include #include #define NCARDS 52 #define NPROPS 2 #define NSUITS 4 #define NFACES 13 // card text values using array
[IN C CODE PLEASE]
#include
#include
#include
#define NCARDS 52
#define NPROPS 2
#define NSUITS 4
#define NFACES 13
// card text values using array of pointers to preinitialized constant text strings
char* suit[NSUITS]={"hearts","spades","clubs","diamonds"};
char* face[NFACES]={"ace","two","three","four","five","six","seven","eight","nine",
"ten","jack","queen","king"};
// function prototypes used for manipulating cards
void PrintCard(int deck[NCARDS][NPROPS], int card);
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 card);
int main()
{
//deck of cards
// face, suite, card value
int deck[NCARDS][NPROPS];
time_t rawtime=time(NULL);
int i;
srand(time(NULL));
// init the deck
// loop on the chards
InitDeck(deck);
ShuffleDeck(deck);
// print the deck
puts("The shuffled deck is:");
for (i=0; i { PrintCard(deck,i); } //deal 5 cards each to two players one at a time; repeat until 5 cards //add the total points in each player's hand //determine winner printf("Printed on %s",ctime(&rawtime)); return 0; } void InitDeck(int deck[NCARDS][NPROPS]) { int suit, face, card; card=0; for (suit=0; suit for (face=0; face { deck[card][0] = suit; deck[card][1] = face; card++; } } void PrintCard(int deck[NCARDS][NPROPS], int card) { int tempface, tempsuit; tempface = deck[card] [1]; tempsuit = deck[card] [0]; //printf("Card %d of suit %d has a face %d ", card, tempsuit, tempface); printf("Card %d suit %s has face %s ", card, suit[tempsuit], face[tempface]); } void ShuffleDeck(int deck[NCARDS][NPROPS]) { int card, dest; for (card=0; card { dest = rand()%NCARDS; SwapCards(deck, card, dest); } } void SwapCards(int deck[NCARDS][NPROPS], int src, int dest) { int tempface, tempsuit; tempface = deck[src] [0]; tempsuit = deck[dest] [1]; deck[src] [0] = deck[dest] [0]; deck[dest][0] = tempsuit; } int GetPlayValue(int deck[NCARDS][NPROPS], int card) { int playval, tface; tface = deck[card][1]; if(tface playval = tface+1; else playval = 10; return playval; }
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