CruceGame  v0.4.0
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
Classes | Functions
deck.h File Reference

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.

Classes

struct  Card
 Card structure, to keep suit and value. More...
 
struct  Deck
 A 28 card deck used in this game. More...
 

Functions

EXPORT struct Carddeck_createCard (const enum Suit suit, const int value)
 Allocates and initializes a card. More...
 
EXPORT int deck_deleteCard (struct Card **card)
 Frees the memory of a card and makes the pointer NULL. More...
 
EXPORT struct Deckdeck_createDeck ()
 Allocates and initializes a deck. More...
 
EXPORT int deck_deckShuffle (struct Deck *deck)
 Shuffles a deck. More...
 
EXPORT int deck_deleteDeck (struct Deck **deck)
 Frees the memory of a deck and sets the pointer to NULL. More...
 
EXPORT int deck_compareCards (const struct Card *card1, const struct Card *card2, const enum Suit trump)
 Compare two cards. More...
 
EXPORT int deck_cardsNumber (const struct Deck *deck)
 The function counts the cards from deck. More...
 

Detailed Description

In this file are located the definitions of Card and Deck structures, as well as helper functions.

Function Documentation

EXPORT int deck_cardsNumber ( const struct Deck deck)

The function counts the cards from deck.

Parameters
deckPointer 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
card1The first card.
card2The second card.
trumpThe 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
suitThe suit of the new card.
valueThe 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
deckThe 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
cardPointer 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
deckPointer to the pointer to be freed.
Returns
NO_ERROR on success, other value on failure.