This file contains implementations of the functions used for game-related operations. More...
#include "game.h"
#include "errors.h"
#include "constants.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Functions | |
struct Game * | game_createGame (const int pointsNumber) |
Allocates memory for and initializes a game. More... | |
int | game_deleteGame (struct Game **game) |
Frees the memory of a game and makes the pointer NULL. More... | |
int | game_addPlayer (struct Player *player, struct Game *game) |
Adds a player to a game. More... | |
int | game_removePlayer (const struct Player *player, struct Game *game) |
Removes a player from a game. More... | |
int | game_addTeam (struct Team *team, struct Game *game) |
Adds a team to a game. More... | |
int | game_removeTeam (const struct Team *team, struct Game *game) |
Removes a team from a game. More... | |
struct Team * | game_winningTeam (struct Game *game) |
Searches the winning team of a game. More... | |
int | maximumValue (struct Card *cards[], const int length, const enum Suit suit) |
Function to find the maximum value of a certain suit. More... | |
int | game_checkCard (struct Player *player, const struct Game *game, struct Hand *hand, const int idCard) |
Function checks if the player can put a card down. More... | |
int | findAllowedCard (const struct Player *player, const struct Game *game, struct Hand *hand, int currentCard, const int searchPattern) |
Helper for function that search for an allowed card. More... | |
int | game_findNextAllowedCard (struct Player *player, struct Game *game, struct Hand *hand, int currentCard) |
Function to find the next allowed card after currentCard. Uses game_checkCard to check if a card is allowed. More... | |
int | game_findPreviousAllowedCard (struct Player *player, struct Game *game, struct Hand *hand, int currentCard) |
Function to find the previous allowed card before currentCard. Uses game_checkCard to check if a card is allowed. More... | |
struct Team * | game_findTeam (const struct Game *game, struct Player *player) |
Function to find the team in which a player belongs. More... | |
int | game_updateScore (const struct Game *game, struct Player *bidWinner) |
Function to update the score of teams and players after a round. More... | |
int | game_arrangePlayersRound (struct Game *game, const int i) |
Function to add a round to a game and to arrange players into it, according to game rules. More... | |
This file contains implementations of the functions used for game-related operations.
int findAllowedCard | ( | const struct Player * | player, |
const struct Game * | game, | ||
struct Hand * | hand, | ||
int | currentCard, | ||
const int | searchPattern | ||
) |
Helper for function that search for an allowed card.
player | The player who's hand is searched. |
game | The game in which the player and the hand belongs. |
hand | The hand where is supposed to put the card. |
currentCard | The cardId to look for. |
searchPattern | Function searches the player's hand using a pattern provided by this argument. Currently, there are allowed only 1 and -1 as search patterns, altough the function may be extended to use other patterns as well. |
Adds a player to a game.
player | The player to be added. |
game | The game where the player is to be added. |
Adds a team to a game.
team | The team to be added. |
game | The game where the team is to be added to. |
int game_arrangePlayersRound | ( | struct Game * | game, |
const int | i | ||
) |
Function to add a round to a game and to arrange players into it, according to game rules.
game | The game to process. |
i | The index of the first player in that round. |
int game_checkCard | ( | struct Player * | player, |
const struct Game * | game, | ||
struct Hand * | hand, | ||
const int | idCard | ||
) |
Function checks if the player can put a card down.
player | The player who wants to put the card down. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
idCard | The id of the card. |
struct Game* game_createGame | ( | const int | numberPoints | ) |
Allocates memory for and initializes a game.
numberPoints | The number of points required for winning the game. |
int game_deleteGame | ( | struct Game ** | game | ) |
Frees the memory of a game and makes the pointer NULL.
game | Pointer to the game to be deleted. |
int game_findNextAllowedCard | ( | struct Player * | player, |
struct Game * | game, | ||
struct Hand * | hand, | ||
int | currentCard | ||
) |
Function to find the next allowed card after currentCard. Uses game_checkCard to check if a card is allowed.
player | The player who has the cards. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
currentCard | Function finds the first allowed card after currentCard. |
int game_findPreviousAllowedCard | ( | struct Player * | player, |
struct Game * | game, | ||
struct Hand * | hand, | ||
int | currentCard | ||
) |
Function to find the previous allowed card before currentCard. Uses game_checkCard to check if a card is allowed.
player | The player who has the cards. |
game | The game where the player is located. |
hand | The hand in which should put the card. |
currentCard | Function finds the last allowed card before currentCard. |
Function to find the team in which a player belongs.
game | The game where to search. |
player | The player to find. |
Removes a player from a game.
player | The player to be removed. |
game | The game from where the player is to be removed. |
Removes a team from a game.
team | The team to be removed. |
game | The game from where the team is to be removed. |
Searches the winning team of a game.
game | The game in which the winning team is to be search. |
Function to find the maximum value of a certain suit.
cards | The card array where to look for. |
length | The length of cards array. |
suit | The suit to search for. |