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

Contains implementations of the functions used for creation or deletion of a round. Also, it contains implementations for the functions used to handle different activities in a round, like removing a player. More...

#include "round.h"
#include "errors.h"
#include <stdlib.h>
#include <stdio.h>

Functions

struct Roundround_createRound ()
 Allocates memory for and initializes a round. More...
 
int round_deleteRound (struct Round **round)
 Frees the memory of a round. Makes NULL pointer. More...
 
struct Handround_createHand ()
 Allocates memory for and initializes a hand. More...
 
int round_deleteHand (struct Hand **hand)
 Frees the memory of a hand. Makes pointer NULL. More...
 
struct Playerround_getBidWinner (const struct Round *round)
 Finds the winner of a bid in a round. More...
 
int round_findPlayerIndexRound (const struct Player *player, const struct Round *round)
 Helper to find player in a round. More...
 
int round_placeBid (const struct Player *player, const int bid, struct Round *round)
 Places the bid of a player. More...
 
int round_addPlayer (struct Player *player, struct Round *round)
 Add a player to a round. More...
 
int round_addPlayerHand (struct Player *player, struct Hand *hand)
 Adds a player to a hand. More...
 
int round_removePlayer (const struct Player *player, struct Round *round)
 Removes a player from a round. More...
 
int round_removePlayerHand (const struct Player *player, struct Hand *hand)
 Removes a player from a hand. More...
 
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...
 
int totalPointsNumber (const struct Hand *hand)
 Function to compute the number of points in a hand. More...
 
struct Playerround_handWinner (const struct Hand *hand, struct Round *round)
 Determines the winner of a hand. More...
 
int round_distributeCard (struct Deck *deck, const struct Round *round)
 Distributes one card to every player. More...
 
int round_distributeDeck (struct Deck *deck, const struct Round *round)
 Distributes cards to players. More...
 
int round_arrangePlayersHand (struct Round *round, int i)
 The function arranges the players in a hand. More...
 
int round_computePoints (const struct Team *team, const struct Round *round)
 Compute round points of a team. More...
 
int round_getMaximumBid (struct Round *round)
 The function search the maximum bid. More...
 
int checkBid (int currentBid, int maximumBid)
 Helper for findAllowedBid().) More...
 
int findAllowedBid (struct Round *round, int currentBid, int searchPattern)
 Helper for functions which search a allowed bid. More...
 
int round_findNextAllowedBid (struct Round *round, int currentBid)
 Function to find the next allowed bid after currentBid. More...
 
int round_findPreviousAllowedBid (struct Round *round, int currentBid)
 Function to find the previous allowed bid before currentBid. More...
 

Detailed Description

Contains implementations of the functions used for creation or deletion of a round. Also, it contains implementations for the functions used to handle different activities in a round, like removing a player.

Function Documentation

int checkBid ( int  currentBid,
int  maximumBid 
)

Helper for findAllowedBid().)

Parameters
currentBidThe bid which is bid.
maximumBidMaximum bid from auction.
Returns
1 if the current bid can be bid, otherwise 0.
int findAllowedBid ( struct Round round,
int  currentBid,
int  searchPattern 
)

Helper for functions which search a allowed bid.

Parameters
roundThe round in which are the bids.
currentBidThe bid which is bid.
searchPatternThis parameter indicate where to search (-1 to left, 1 to right).
Returns
The first allowed bid found.
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.
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.
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.
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.
struct Hand* round_createHand ( )

Allocates memory for and initializes a hand.

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

Allocates memory for and initializes a round.

Returns
Pointer to the new round on success or NULL on failure.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
int totalPointsNumber ( const struct Hand hand)

Function to compute the number of points in a hand.

Parameters
handThe hand where to compute the number of points.
Returns
The number of points in hand on succes, negative otherwise.