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

Round and Hand structures, as well as helper functions. More...

#include "platform.h"
#include "deck.h"
#include "team.h"
#include "constants.h"
#include "errors.h"

Go to the source code of this file.

Classes

struct  Hand
 Hand structure. More...
 
struct  Round
 Round structure. More...
 

Functions

EXPORT struct Playerround_getBidWinner (const struct Round *round)
 Finds the winner of a bid in a round. More...
 
EXPORT int round_placeBid (const struct Player *player, const int bid, struct Round *round)
 Places the bid of a player. More...
 
EXPORT int round_addPlayer (struct Player *player, struct Round *round)
 Add a player to a round. More...
 
EXPORT int round_findPlayerIndexRound (const struct Player *player, const struct Round *round)
 Helper to find player in a round. More...
 
EXPORT int round_addPlayerHand (struct Player *player, struct Hand *hand)
 Adds a player to a hand. More...
 
EXPORT int round_putCard (struct Player *player, const int cardId, const int handId, struct Round *round)
 Places a card from a player to a hand and offers the player 20 points if has 3 and 4 of same suit or 40 points if has 3 and 4 of same suit as the trump. More...
 
EXPORT struct Roundround_createRound ()
 Allocates memory for and initializes a round. More...
 
EXPORT int round_deleteRound (struct Round **round)
 Frees the memory of a round. Makes NULL pointer. More...
 
EXPORT struct Handround_createHand ()
 Allocates memory for and initializes a hand. More...
 
EXPORT int round_deleteHand (struct Hand **hand)
 Frees the memory of a hand. Makes pointer NULL. More...
 
EXPORT int round_removePlayer (const struct Player *player, struct Round *round)
 Removes a player from a round. More...
 
EXPORT int round_removePlayerHand (const struct Player *player, struct Hand *hand)
 Removes a player from a hand. More...
 
EXPORT struct Playerround_handWinner (const struct Hand *hand, struct Round *round)
 Determines the winner of a hand. More...
 
EXPORT int round_distributeCard (struct Deck *deck, const struct Round *round)
 Distributes one card to every player. More...
 
EXPORT int round_distributeDeck (struct Deck *deck, const struct Round *round)
 Distributes cards to players. More...
 
EXPORT int round_arrangePlayersHand (struct Round *round, int i)
 The function arranges the players in a hand. More...
 
EXPORT int round_computePoints (const struct Team *team, const struct Round *round)
 Compute round points of a team. More...
 
EXPORT int round_getMaximumBid (struct Round *round)
 The function search the maximum bid. More...
 
EXPORT int round_findNextAllowedBid (struct Round *round, int currentBid)
 Function to find the next allowed bid after currentBid. More...
 
EXPORT int round_findPreviousAllowedBid (struct Round *round, int currentBid)
 Function to find the previous allowed bid before currentBid. More...
 

Detailed Description

Round and Hand structures, as well as helper functions.

Function Documentation

EXPORT int round_addPlayer ( struct Player player,
struct Round round 
)

Add a player to a round.

Parameters
playerPointer to the player to be added.
roundPointer to the round where to add player.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_addPlayerHand ( struct Player player,
struct Hand hand 
)

Adds a player to a hand.

Parameters
playerPointer to the player to be added.
handPointer to the hand where the player is to be added.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_arrangePlayersHand ( struct Round round,
int  i 
)

The function arranges the players in a hand.

Parameters
roundPointer to the round from which arranges it the players.
iThe position from where begin arranging.
Returns
NO_ERROR or 0 on success, other value on failure.
EXPORT int round_computePoints ( const struct Team team,
const struct Round round 
)

Compute round points of a team.

Parameters
teamThe team to compute points for.
roundThe round where to compute points.
Returns
Number of round points on success, other value on failure.
EXPORT struct Hand* round_createHand ( )

Allocates memory for and initializes a hand.

Returns
Pointer to the new hand on success or NULL on failure.
EXPORT struct Round* round_createRound ( )

Allocates memory for and initializes a round.

Returns
Pointer to the new round on success or NULL on failure.
EXPORT int round_deleteHand ( struct Hand **  hand)

Frees the memory of a hand. Makes pointer NULL.

Parameters
handPointer to pointer to the hand to be deleted.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_deleteRound ( struct Round **  round)

Frees the memory of a round. Makes NULL pointer.

Parameters
roundPointer to pointer to the round to be deleted.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_distributeCard ( struct Deck deck,
const struct Round round 
)

Distributes one card to every player.

Parameters
deckPointer to the deck from where cards are distributed.
roundPointer to the round containing the players that receive the cards.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_distributeDeck ( struct Deck deck,
const struct Round round 
)

Distributes cards to players.

Parameters
deckPointer to the deck from where cards are distributed.
roundPointer to the round that deck is distributed to.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_findNextAllowedBid ( struct Round round,
int  currentBid 
)

Function to find the next allowed bid after currentBid.

Parameters
roundThe round where are bids.
currentBidFunction finds the first allowed bid after currentBid.
Returns
The next allowed bid's id on success, negative value on failure.
EXPORT int round_findPlayerIndexRound ( const struct Player player,
const struct Round round 
)

Helper to find player in a round.

Parameters
playerPlayer to find.
roundRound to search for player.
Returns
Id of the player if found, negative value otherwise.
EXPORT int round_findPreviousAllowedBid ( struct Round round,
int  currentBid 
)

Function to find the previous allowed bid before currentBid.

Parameters
roundThe round where are bids.
currentBidFunction finds the first allowed bid before currentBid.
Returns
The previous allowed bid's id on success, negative value on failure.
EXPORT struct Player* round_getBidWinner ( const struct Round round)

Finds the winner of a bid in a round.

Parameters
roundPointer to the round where to find the bid winner.
Returns
Pointer to the bid winner player on success or NULL on failure.
EXPORT int round_getMaximumBid ( struct Round round)

The function search the maximum bid.

Parameters
roundPointer to the round in which are the bids.
Returns
The maximum bid.
EXPORT struct Player* round_handWinner ( const struct Hand hand,
struct Round round 
)

Determines the winner of a hand.

Parameters
handPointer to the hand.
roundPointer to the round containing the hand that the player won.
Returns
Pointer to the winning player or NULL on failure.
EXPORT int round_placeBid ( const struct Player player,
const int  bid,
struct Round round 
)

Places the bid of a player.

Parameters
playerPointer to the player who places the bid.
bidThe value of the bid.
roundPointer to the round where to place the bid.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_putCard ( struct Player player,
const int  cardId,
const int  handId,
struct Round round 
)

Places a card from a player to a hand and offers the player 20 points if has 3 and 4 of same suit or 40 points if has 3 and 4 of same suit as the trump.

Parameters
playerPointer to the player who places the card.
cardIdId of the card placed by the player (id from Player.cards).
handIdId of the hand in which the card is placed.
roundPointer to the round in which is hand.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_removePlayer ( const struct Player player,
struct Round round 
)

Removes a player from a round.

Parameters
playerPointer to the player to be removed.
roundPointer to the round from which the player is removed.
Returns
NO_ERROR on success, other value on failure.
EXPORT int round_removePlayerHand ( const struct Player player,
struct Hand hand 
)

Removes a player from a hand.

Parameters
playerPointer to the player to be removed.
handPointer to the hand from where the player is removed.
Returns
NO_ERROR on success, other value on failure.