Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

UNO Card game in C. I have to code the game of UNO in C. And I have to use linke

ID: 3716000 • Letter: U

Question

UNO Card game in C.

I have to code the game of UNO in C. And I have to use linked lists for the deck and the two players list.

I just really need help coding how to create a discard pile and a function to draw cards from the draw pile (if the user cannot play a card in their hand). I just need help finishing this code because I don't know what to do.

Here are the guidelines for the project:

Please note that the sample code isn't exactly how the code has to be executed... they are more like guidelines.

This is the code I have so far:

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <time.h>

typedef struct card_s {

char suit [7];

int value;

char action[15];

struct card_s *pt;

} card;

struct card_s* CreateDeck(){

  

card *headp=NULL, *temp, *tail=NULL;

  

FILE *fp;

fp = fopen("Uno_Deck.txt", "r"); //open file wiht 108 uno cards

  

//This creates the linked list from the file

temp = (card *)malloc(sizeof (card));

while (fscanf(fp, "%s %d %s", temp->suit, &temp->value, temp->action) != EOF){

if (headp == NULL){

headp = temp;

}

else {

tail->pt = temp;

}

tail = temp;

tail->pt = NULL;

temp = (card *) malloc(sizeof (card));

}

fclose(fp); //Closes file

return headp;

}

void Print(card *headp){ //prints list

while (headp != NULL){

printf("%s %d %s ", headp->suit, headp->value, headp->action);

headp = headp->pt;

}

printf(" ");

}

struct card_s* ShuffleCard(struct card_s* deck){

struct card_s* crd;

int n,i,j,k;

  

struct card_s** arr; //We will store as array for shuffling

  

for (n=0, crd=deck;crd!=NULL;n++,crd = crd->pt){

arr = (struct card_s**)malloc (n * sizeof(struct card_s*)); //allocates memory

}

for (i=0, crd = deck; crd != NULL; i++, crd=crd->pt){

arr[i]=crd;

}

  

for (i=0; i<1000; i++){

for (j=0; j<n; j++){

k=rand()%n;

crd=arr[j];

arr[j]=arr[k];

arr[k]=crd;

}

}

  

for (i=0; i<n-1;i++){

arr[i]->pt = arr[i+1];

}

  

arr[i]->pt=NULL;

crd=arr[0];

  

  

return crd;

}

void Deal_Hands(struct card_s** deck, struct card_s** hand1, struct card_s** hand2, int n) {

  

struct card_s *cur, *cur1, *cur2; //Stores current card in 3 lists

int i;

cur1 = NULL;

cur2 = NULL;

cur = *deck;

for(i = 0; i < 2 * n && cur != NULL; i++, cur = cur->pt) {

if(i % 2 == 0) { //Player 1's turn (even)

if(cur1 == NULL) { //Refers to first element(card) in list

*hand1 = cur;

} else {

cur1->pt = cur;

}

cur1 = cur;

}

else { //Player 2's turn (odd)

if(cur2 == NULL) { //Refers to first element(card) in list

*hand2 = cur;

}

else {

cur2->pt = cur;

}

cur2 = cur;

}

}

cur1->pt = cur2->pt = NULL; //Ends the lists with NULL

*deck = cur; //Updates the deck witht the remaining elements(cards)

}

void drawCard (struct card_s** deck, struct card_s** discard){

}

void HandToDiscard (struct card_s** hand, struct card_s** discard){

}

int main(void) {

int choice;

  

struct card_s *deck, *hand1, *hand2, *discard;

  

srand(time(NULL)); //Random Number

deck = CreateDeck();

  

printf("Let's Play a Game of UNO! ");

printf("Press 1 to shuffle the UNO deck or 2 to load a deck from a file: ");

scanf("%d", &choice);

if (choice == 1){

deck = ShuffleCard(deck); //shuffles deck from file

Print(deck); //prints shuffled deck

  

}

if (choice == 2){

//printf("The deck has been loaded in. ");

Print(deck); //prints the deck from file

}

printf(" -------------------------- Playing UNO with 2 players -------------------------- ");

Deal_Hands(&deck, &hand1, &hand2, 7);//two hands are dealt from the deck with 7 cards

  

printf("Player 1's hand: ");

Print(hand1);

  

printf("Player 2's hand: ");

Print(hand2);

  

  

  

/*

   Next we have to create a discard pile from the first node of the rest of the hand after it is dealt.

   Then we print the discard pile.

   Then we ask player one to play a card. Check to see if color OR number match, and if it does, add it to the front of the discard pile linked list. If neither match, then say that card is unplayable and to pick a different card or press 0 to draw from deck.

   If either one of the players hands are empty then round is over. Take opponents total score of each card and award them to the winner. If score > 500 then player wins.

   */

  

free(deck);

free(hand1);

free(hand2);

return 0;

}

2 A Game of UNO You are to develop an interactive game of UNO between two players. The gameplay for UNO is described at https://www.unorules.com/. Your program should operate as follows. 2.1 Setup 1. UNO cards are represented as variables of the following type: typedef struct card.s f char suit [7) int value; char action [15) struct card s 'pt; card You are allowed to add attributes to this definition, but not to remove any. You can represent colors by using card suits. Red: hearts; Yellow: diamonds; Green: clubs; Blue: spades. The action field is used to denote the function of action cards. 2. The game is played using the following deck of cards 01 2 34 5 678 900 02 3 4 5 678 9 00 1213 4 5 68 9OG 213 45 678 9OG 21 3 4 5 617 8 90 213 4 5 6789 OG Figure 1: The deck of UNO cards. The following action cards are included Reverse If going clockwise, switch to counterclockwise or vice versa. . Skip- When a player places this card, the next player has to skip their turn. If turned up at the beginning, the first player loses his/her turn. Draw Two- When a person places this card, the next player will have to pick up two cards and forfeit his/her turn. by Dmitry Fomin https://commons.wikisedia.org/w/index.php?curid-29517498

Explanation / Answer

Case Study Definitions:

Selection of unicode game theory specifies the game options with certain information rules to exchange the code sequence by using programming language.

Algorithm Exercise:

Line 1: INPUT - Let's Play a Game of UNO by using key values;

Line 2: Enter / Press 1 to shuffle the UNO deck or 2 to load a deck from a file to start;

Line 3: Enter - The deck has been loaded in the system process deck of cards;

Line 4: If 'x' & 'y' predefinded sequence from a file to process deck of cards;

Line 5: If cards can be executed with following conditions : Reverse, skip, drawto;

Line 6: If conditions can choose the users set of desk of files in key values.

Line 7: If the deck is implemented by the dynamic set of cards;

Line 8: If the deck list is populated with cards to each others;

Line 9: Adding the value to the each deck of the cards to process by key;

Line 10: Display cards is implemented by the dynamic list;

Line 11: Display cards can be obtained by dispatch card has exhausted & game not ended.

Line 12: OUTPUT - Display set of cards by selecting in sequence.

Line 13: END CODE

------------------------------------------------------------------------------------------------------------

Programming Language : The Gameplay for UNO by using Game Theory.

#include <stdio.h>

#include <stdlib.h>

#include<conio.h>

#include <string.h>

#include <time.h>

#include<math.h>

#include<alloc.h>

Void Main( )

{

typedef struct card_s

{

char suit [7];

int value;

char action[15];

struct card_s *pt;

}

card;

struct card_s* CreateDeck()

{

card *headp=NULL, *temp, *tail=NULL;

FILE *fp;

fp = fopen("Uno_Deck.txt", "r"); //open file with 108 uno cards

//This creates the linked list from the file

temp = (card *)malloc(sizeof (card));

while (fscanf(fp, "%s %d %s", temp->suit, &temp->value, temp->action) != EOF)

{

if (headp == NULL)

{

headp = temp;

}

else

{

tail->pt = temp;

}

tail = temp;

tail->pt = NULL;

temp = (card *) malloc(sizeof (card));

}

fclose(fp); //Closes file

return headp;

}

void Print(card *headp)

{

//prints list

while (headp != NULL)

{

printf("%s %d %s ", headp->suit, headp->value, headp->action);

headp = headp->pt;

}

printf(" ");

}

struct card_s* ShuffleCard(struct card_s* deck)

{

struct card_s* crd;

int n,i,j,k;

struct card_s** arr; //We will store as array for shuffling

for (n=0, crd=deck;crd!=NULL;n++,crd = crd->pt)

{

arr = (struct card_s**)malloc (n * sizeof(struct card_s*)); //allocates memory

}

for (i=0, crd = deck; crd != NULL; i++, crd=crd->pt)

{

arr[i]=crd;

}

for (i=0; i<1000; i++)

{

for (j=0; j<n; j++)

{

k=rand()%n;

crd=arr[j];

arr[j]=arr[k];

arr[k]=crd;

}

}

for (i=0; i<n-1;i++){

arr[i]->pt = arr[i+1];

}

arr[i]->pt=NULL;

crd=arr[0];

return crd;

}

void Deal_Hands(struct card_s** deck, struct card_s** hand1, struct card_s** hand2, int n)

{

struct card_s *cur, *cur1, *cur2; //Stores current card in 3 lists

int i;

cur1 = NULL;

cur2 = NULL;

cur = *deck;

for(i = 0; i < 2 * n && cur != NULL; i++, cur = cur->pt) {

if(i % 2 == 0)

{

//Player 1's turn (even)

if(cur1 == NULL)

{

//Refers to first element(card) in list

*hand1 = cur;

}

else

{

cur1->pt = cur;

}

cur1 = cur;

}

else

{

//Player 2's turn (odd)

if(cur2 == NULL)

{

//Refers to first element(card) in list

*hand2 = cur;

}

Else

{

cur2->pt = cur;

}

cur2 = cur;

}

}

cur1->pt = cur2->pt = NULL; //Ends the lists with NULL

*deck = cur; //Updates the deck witht the remaining elements(cards)

}

void drawCard (struct card_s** deck, struct card_s** discard)

}

}

void HandToDiscard (struct card_s** hand, struct card_s** discard)

{

{

int main(void)

{

int choice;

struct card_s *deck, *hand1, *hand2, *discard;

srand(time(NULL)); //Random Number

deck = CreateDeck( );

printf("Let's Play a Game of UNO! ");

printf("Press 1 to shuffle the UNO deck or 2 to load a deck from a file: ");

scanf("%d", &choice);

if (choice == 1)

{

deck = ShuffleCard(deck); //shuffles deck from file

Print(deck); //prints shuffled deck

}

if (choice == 2)

{

//printf("The deck has been loaded in. ");

Print(deck); //prints the deck from file

}

printf(" -------------------------- Playing UNO with 2 players -------------------------- ");

Deal_Hands(&deck, &hand1, &hand2, 7);//two hands are dealt from the deck with 7 cards

printf("Player 1's hand: ");

Print(hand1);

printf("Player 2's hand: ");

Print(hand2);

free(deck);

free(hand1);

free(hand2);

return 0;

getch( );

}

}

}

---------------------------------------------------------------------------------------------------------------

OUTPUT:

Graphical User Interface (GUI) display the cards on the screen by using any C text editor / TurboC2 editor.