In this file are defined functions used for deck-related operations, these functions are declared in the header file deck.h. More...
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "deck.h"
#include "errors.h"
#include "constants.h"
#include <stdio.h>
Functions | |
struct Card * | deck_createCard (const enum Suit suit, const int value) |
Allocates and initializes a card. More... | |
int | deck_deleteCard (struct Card **card) |
Frees the memory of a card and makes the pointer NULL. More... | |
struct Deck * | deck_createDeck () |
Allocates and initializes a deck. More... | |
int | deck_deleteDeck (struct Deck **deck) |
Frees the memory of a deck and sets the pointer to NULL. More... | |
void | deck_swap (struct Card **a, struct Card **b) |
Swap 2 Cards. More... | |
int | deck_deckShuffle (struct Deck *deck) |
Shuffles a deck. More... | |
int | deck_compareCards (const struct Card *card1, const struct Card *card2, const enum Suit trump) |
Compare two cards. More... | |
int | deck_cardsNumber (const struct Deck *deck) |
The function counts the cards from deck. More... | |
Variables | |
const int | VALUES [] = {2, 3, 4, 0, 10, 11, -1} |
Game values for cards. More... | |
In this file are defined functions used for deck-related operations, these functions are declared in the header file deck.h.
int deck_cardsNumber | ( | const struct Deck * | deck | ) |
The function counts the cards from deck.
deck | Pointer to the deck from which it counts. |
int deck_compareCards | ( | const struct Card * | card1, |
const struct Card * | card2, | ||
const enum Suit | trump | ||
) |
Compare two cards.
card1 | The first card. |
card2 | The second card. |
trump | The trump of the round. |
Allocates and initializes a card.
suit | The suit of the new card. |
value | The value of the new card. |
struct Deck* deck_createDeck | ( | ) |
Allocates and initializes a deck.
This function initializes a deck by iterating over all values and suits available. The deck will be always the same.
int deck_deckShuffle | ( | struct Deck * | deck | ) |
Shuffles a deck.
This function randomly shuffles the deck. It uses rand function from stdlib with time as seed. The shuffle is performed by random swaps. The number of swaps is also random, but it is at least SWAP_MIN and smaller then SWAP_MAX.
int deck_deleteCard | ( | struct Card ** | card | ) |
Frees the memory of a card and makes the pointer NULL.
card | Pointer to the pointer to be freed. |
int deck_deleteDeck | ( | struct Deck ** | deck | ) |
Frees the memory of a deck and sets the pointer to NULL.
deck | Pointer to the pointer to be freed. |
Swap 2 Cards.
Helper for deckShuffle
a | |
b |
const int VALUES[] = {2, 3, 4, 0, 10, 11, -1} |
Game values for cards.
Constants for game values