Hey,
I need to create a war card game.
I have a problem with linked list - I read about it but still I have a problem with writing the code.
I made a deck of shuffled card and now I need to sort it out between 2 players... so I want the deck to be a list so i will always be able to compare the cards
Here is part of my code, I would appreciate any help!
Thanks!!
typedef struct card
{
int rank;
int suit;
}card;
typedef struct deck {
int num_cards;
card **cards;
struct deck *next;
} deck;
deck *shuffle(deck *deck1) //shuffle the deck
{
int check[4][13] = { 0 };
for (int i = 0; i < DECKSIZE; i++)
{
int getVal = rand() % 13;
int getSuit = rand() % 4;
if (check[getSuit][getVal] >= 1)
{
i--;
continue;
}
deck1->cards[i] = make_card(getSuit, getVal); //didn't insert the mark_card function
check[getSuit][getVal]++;
}
return deck1;
}
deck *addPlayer1(deck *shuffledpile, deck *top, deck *bottom)
{
deck *pile1 = malloc(sizeof(deck));;
pile1->num_cards = 26;
pile1->cards = malloc(26 * sizeof(card *));
int i;
for (i = 0; i < DECKSIZE / 2; i++)
{
pile1->cards[i] = shuffledpile->cards[i];
pile1->next = bottom;
}
top->cards[i];
return pile1;
}
int main()
{
deck *pile = makeDeck(); //didn't insert the makeDeck fuction- but it works
deck *deckShuffled = shuffle(pile);
deck *Atop=NULL, *Abot=NULL;
deck *player1=addPlayer1(deckShuffled,Atop, Abot);
}