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;
}
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.
Need help with shuffle function and give 8 cards to user and computer from shuffle deck?...
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 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 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 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...
I'm writing code for a poker game and I'm not sure where I'm going wrong with it. My compiler is sending back errors for lines (typedef int bool)(the two char* declarations) and the two functions before my if else statement (approx lines 109). #include <stdio.h> #include <stdlib.h> #include <time.h> #define SUITS 4 #define FACES 13 #define AVAILABLE 0 #define TAKEN 1 #define SIZE 5 #define TRUE 1 #define FALSE 0 void dealACard(char *suits[], char *faces[], int deck[][FACES]); void dealAHand(char *suits[],...
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...
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...
Here is a function for some code im working on in C. Right now it accepts 2 different user inputs and stores them as city and distance. What I want is for the user to input only once. For example "Enter the city name and distance from previous city: Arlington 200". I need to separate that string into values for city and distance. I think I need to use tokens but im not sure how. void addCity () { char...
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...
This code in c evaluates a mathematical expression and checks that it is correctly balanced, then converts the expression to its postfix form (This part works). Now I need to evaluate the postfix expression with a function. I've been compiling it using dev c ++. #include #include #define SIZE 20 #include int profundidad(char expresion[]); int prec(char op1, char op2); void postfijo(char expresion[]); char funcion[SIZE]; float convierte(char car); float resultado(float opnd1, char symb, float opnd2); float evaluar(char expresion[]); #define SIZE 20...