In this file are located the definitions of Card and Deck structures, as well as helper functions.
More...
#include "platform.h"
#include "constants.h"
Go to the source code of this file.
In this file are located the definitions of Card and Deck structures, as well as helper functions.
EXPORT int deck_cardsNumber |
( |
const struct Deck * |
deck | ) |
|
The function counts the cards from deck.
- Parameters
-
deck | Pointer to the deck from which it counts. |
- Returns
- The cards number from deck.
EXPORT int deck_compareCards |
( |
const struct Card * |
card1, |
|
|
const struct Card * |
card2, |
|
|
const enum Suit |
trump |
|
) |
| |
Compare two cards.
- Parameters
-
card1 | The first card. |
card2 | The second card. |
trump | The trump of the round. |
- Returns
- 0 If the cards are equal. 1 If the first card is winning. 2 If the second card is winning. Other value on failure.
EXPORT struct Card* deck_createCard |
( |
const enum Suit |
suit, |
|
|
const int |
value |
|
) |
| |
Allocates and initializes a card.
- Parameters
-
suit | The suit of the new card. |
value | The value of the new card. |
- Returns
- Pointer to the new card on success or NULL on failure.
EXPORT struct Deck* deck_createDeck |
( |
| ) |
|
Allocates and initializes a deck.
- Returns
- Pointer to the new deck on success or NULL on failure.
This function initializes a deck by iterating over all values and suits available. The deck will be always the same.
EXPORT int deck_deckShuffle |
( |
struct Deck * |
deck | ) |
|
Shuffles a deck.
- Parameters
-
deck | The deck to be shuffled. |
- Returns
- NO_ERROR on success, other value on failure.
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.
EXPORT int deck_deleteCard |
( |
struct Card ** |
card | ) |
|
Frees the memory of a card and makes the pointer NULL.
- Parameters
-
card | Pointer to the pointer to be freed. |
- Returns
- NO_ERROR on success, other value on failure.
EXPORT int deck_deleteDeck |
( |
struct Deck ** |
deck | ) |
|
Frees the memory of a deck and sets the pointer to NULL.
- Parameters
-
deck | Pointer to the pointer to be freed. |
- Returns
- NO_ERROR on success, other value on failure.