Question

Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...

Need help with shuffle function and give 8 cards to user and computer from shuffle deck?

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>

typedef struct card_s{
    char suit;
    int face;
    struct card_s *listp;
} card;

void card_create(card* thisNode, char cardSuit, int cardFace, card* nextLoc) {
    thisNode->suit = cardSuit;
    thisNode->face = cardFace;
    thisNode->listp = nextLoc;
    return;
}
void card_insertAfter(card* thisNode, card* newNode) {
    card* tmpNext = NULL;
    tmpNext = thisNode->listp;
    thisNode->listp = newNode;
    newNode->listp = tmpNext;
    return;
}

void card_Print(card* thisNode) {
    if (thisNode->face == -1) {
        printf(" ");
    }
    else if (thisNode->face == 1) {
        printf("A");
    }
    else if (thisNode->face == 11) {
        printf("J");
    }
    else if (thisNode->face == 12) {
        printf("Q");
    }
    else if (thisNode->face == 13) {
        printf("K");
    }
    else {
        printf("%d", thisNode->face);
    }
    if (thisNode->suit == ' ')
        printf("");
    else if (thisNode->suit == 'H')
        printf( " of Hearts\n");
    else if (thisNode->suit == 'C')
        printf(" of Clubs\n");
    else if (thisNode->suit == 'D')
        printf(" of Diamonds\n");
    else if (thisNode->suit == 'S')
        printf(" of Spades\n");
    return;
}

void swap(card *a, card *b) {
    card temp = *a;
    *a = *b;
    *b = temp;
}

void delnode(card *head, int coordinate)
{
    card *current = head;
    card *victim = current;
    int count = 1;
  
    if (coordinate == 0) {
        head = current->listp;
        free(victim);
        return;
    }
    while (current != NULL)
    {
        if (count == coordinate) {
            victim = current->listp;
            current->listp = current->listp->listp;
            free(victim);
            return;
        }
        count++;
        current = current->listp;
    }
}
card* card_GetNext(card* thisNode) {
    return thisNode->listp;
}

void printintro() {
    printf("|------- ------- ------- -------|\n");
    printf("|------- ------- ------- -------|\n");
    printf("     Let's play Crazy Eight\n");
    printf("|------- ------- ------- -------|\n");
    printf("|------- ------- ------- -------|\n\n");
  
    printf("|Simple Rules                           |\n");
    printf("|Card(s) that can be played             |\n");
    printf("|-Suit matched with top card or         |\n");
    printf("|-Face matched with top card or         |\n");
    printf("|------- ------- ------- ------- -------|\n");
    printf("|------- ------- ------- ------- -------|\n\n");
  
}
void shuffle_cards(card *h, int n) {
    card *D_1 = h;
    srand(time(NULL));
    int i = n - 1;
    while (i > 0){
        i--;
        int j = rand() % (i + 1);
        swap(&D_1[i], &D_1[j]);
    }
}
int main() {
    int deck[52];
    char username[25];
    int random = 0;
    int i = 0;
    card* headObj = NULL;
    card* currObj = NULL;
    card* lastObj = NULL;
    card userhand[8];
    card comphand[8];
  
    printintro();
    printf("Enter your name: ");
    scanf("%s", &username);
  
    printf("\nMain Deck \n\n");
    headObj = (card*)malloc(sizeof(card));
    card_create(headObj, ' ', -1, NULL);
    lastObj = headObj;
    for (int j = 0; j < 4; j++) {
        for (i = 1; i < 14; ++i) {
            if (j == 0) {
                currObj = (card*)malloc(sizeof(card));
                card_create(currObj, 'H', i, NULL);
                card_insertAfter(lastObj, currObj);
                lastObj = currObj;
            }
            else if (j == 1) {
                currObj = (card*)malloc(sizeof(card));
                card_create(currObj, 'D', i, NULL);
                card_insertAfter(lastObj, currObj);
                lastObj = currObj;
            }
            else if (j == 2) {
                currObj = (card*)malloc(sizeof(card));
                card_create(currObj, 'S', i, NULL);
                card_insertAfter(lastObj, currObj);
                lastObj = currObj;
            }
            else if (j == 3) {
                currObj = (card*)malloc(sizeof(card));
                card_create(currObj, 'C', i, NULL);
                card_insertAfter(lastObj, currObj);
                lastObj = currObj;
            }
        }
    }
    currObj = headObj;
    while (currObj != NULL) {
        card_Print(currObj);
        currObj = card_GetNext(currObj);
    }
    printf("\n\n");
    return 0;
}

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • Deck of Cards Program I need help printing a flush, which is showing the top 5...

    Deck of Cards Program I need help printing a flush, which is showing the top 5 cards of the same suite. Below is the code I already have that answers other objectives, such as dealing the cards, and finding pairs. Towards the end I have attempted printing a flush, but I cannot figure it out. public class Shuffler {    /**    * The number of consecutive shuffle steps to be performed in each call    * to each sorting...

  • Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack...

    Given these three classes: Card, DeckOfCards, and DeckOfCardsTest. Extend the DeckofCards class to implement a BlackJack class, which implements a BlackJack game. Please do not use any java applet on the coding. Hint: Use a test class to test above classes. Pulic class Card {    private final String face; // face of card ("Ace", "Deuce", ...)    private final String suit; // suit of card ("Hearts", "Diamonds", ...)    // two-argument constructor initializes card's face and suit    public...

  • //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards...

    //main.cpp #include <iostream> #include <iomanip> #include "deck-of-cards.hpp" void RunAllTests() { int count; std::cin >> count; DeckOfCards myDeckOfCards; for (int i = 0; myDeckOfCards.moreCards() && i < count; ++i) { std::cout << std::left << std::setw(19) << myDeckOfCards.dealCard().toString(); if (i % 4 == 3) std::cout << std::endl; } } int main() { RunAllTests(); return 0; } //card.hpp #ifndef CARD_HPP_ #define CARD_HPP_ #include <string> class Card { public: static const int totalFaces = 13; static const int totalSuits = 4; Card(int cardFace, int...

  • Deleting multiples of a given integer from a linked list: #include <stdio.h> #include <stdlib.h> #include <assert.h>...

    Deleting multiples of a given integer from a linked list: #include <stdio.h> #include <stdlib.h> #include <assert.h> #define MAX 10000 typedef struct node_tag { int v; // data struct node_tag * next; // A pointer to this type of struct } node; // Define a type. Easier to use. node * create_node(int v) { node * p = malloc(sizeof(node)); // Allocate memory assert(p != NULL); // you can be nicer // Set the value in the node. p->v = v; p->next...

  • Hi, I need to make a program in C that reads the type of currency and...

    Hi, I need to make a program in C that reads the type of currency and organizes them into stacks based on currency which can be read back. This is what I have so far, can I get help finishing it? #include <stdio.h> #include <stdlib.h> const float POUND = 1.31; const float YEN = 0.0091; const float RUPEE = 0.014; const float EURO = 1.11; char c; int currValue; float exchangeValue; float finValue; int printValue; struct node {    int...

  • C Programming The following code creates a deck of cards, shuffles it, and deals to players....

    C Programming The following code creates a deck of cards, shuffles it, and deals to players. This program receives command line input [1-13] for number of players and command line input [1-13] for number of cards. Please modify this code to deal cards in a poker game. Command line input must accept [2-10] players and [5] cards only per player. Please validate input. Then, display the sorted hands, and then display the sorted hands - labeling each hand with its...

  • Please help in answering these questions: 1 Line 92 deck is a calling parameter. The received...

    Please help in answering these questions: 1 Line 92 deck is a calling parameter. The received number of that parameter is what? copy of original value pointer 2 Line 92, src is a calling parameter. The received number of that parameter is what? copy of original value pointer 3 Line 95 is a debugging technique where the computer prints what it is doing. Give the line number of a similar line in the example 99 101 108 113 4 Line...

  • HELP NEED!! Can some modified the program Below in C++ So that it can do what...

    HELP NEED!! Can some modified the program Below in C++ So that it can do what the Problem below asked it today???? #include <iostream> #include <stdlib.h> #include <string> #include <time.h> /* time */ #include <sstream> // for ostringstream using namespace std; // PlayingCard class class PlayingCard{ int numRank; int numSuit; string rank; string suit; public: PlayingCard(); PlayingCard(int numRank,int numSuit); void setRankString(); void setSuitString(); void setRank(int numRank); void setSuit(int numSuit); string getRank(); string getSuit(); int getRankNum(); int getSuitNum(); string getCard(); };...

  • (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card...

    (Card Shuffling and Dealing) Modify the program below so that the card-dealing function deals a five-card poker hand. Then write the following additional functions: a) Determine whether the hand contains two pairs b) Determine whether the hand contains a full house (i.e., three of a kind with pair). c) Determinewhetherthehandcontainsastraight flush (i.e.,fivecardsofconsecutivefacevalues). d) Determine whether the hand contains a flush (i.e., five of the same suit) #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define CARDS...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT