Functions
CardGameTools Namespace Reference

Contain all the functions to the coding game. More...

Functions

string convertStructToString (datasplayer *pPlayer)
 Generate a data in a single line from the data of the player.
 
datasplayerconvertStringToStuct (string pPlayer)
 Generate a datasgame struct from a single line

 
string getNUMCookie (std::vector< HTTPCookie > pCookieVector)
 Get the cookie of the game from the list of the cookies

 
string getValue (string pName)
 Get all personnal information from the cookie's Id.
 
string getFileGame (string pName)
 Get all game information from the name of the player.
 
datasgamegetGame (string pName)
 Convert the data to the datasgame struct.
 
void writeValue (string pName, string pValue)
 Write data in the cookie file.
 
void writeFileGame (string pName, string pValue)
 Write data in the game file.
 
void writeGame (datasplayer *pPlayer, datasgame *pGame)
 Write datasgame struct in the game file.
 
string generateUnicCookie ()
 generate an unique id
 
int countGame ()
 Read the game file and count the number of games.
 
vector< string > * loadAndMixCards ()
 Generate a mixed cards list.
 
int calculateCard (string pCard)
 Return the value of the card.
 
datasgamecreateGame (datasplayer *vPlayer)
 Create a game from the data of the player.
 
void drawCards (vector< string > *cardList)
 Draw the cards list.
 
void writeWinner (datasplayer *vPlayer, datasgame *pGame)
 Draw the winner informations.
 
void drawInfos (datasplayer *vPlayer)
 Draw player informations.
 
void drawPlayers (datasgame *pGame)
 Draw players game informations.
 
void drawCardInPlay (datasgame *pGame)
 Draw the cards in the table.
 
void drawPlayerCards (datasplayer *vPlayer)
 Draw the cards of the player.
 
void playACard (datasplayer *vPlayer, datasgame *readedGame, string *card)
 The algorithm when a card is played.
 
void turnPlayers (datasplayer *vPlayer, datasgame *readedGame)
 Change the hand in the game.
 
bool testCard (datasplayer *vPlayer, datasgame *readedGame, string *card)
 Test if the card is playable.
 
void IAPlay (datasgame *readedGame, int pId)
 AI algorithme for one AI player.
 
void gameRules (datasplayer *vPlayer, string *action, string *card)
 The rules Algorithm.
 

Detailed Description

Contain all the functions to the coding game.

Function Documentation

◆ calculateCard()

int CardGameTools::calculateCard ( string  pCard)

Return the value of the card.

Parameters
pCard: The card to evaluate
Returns
the value of the card

Definition at line 788 of file cardgame.cpp.

Referenced by gameRules().

◆ convertStringToStuct()

datasplayer * CardGameTools::convertStringToStuct ( string  pPlayer)

Generate a datasgame struct from a single line

The separator in the string is the double of the character ":" . The real code is "::". The double code "||" define the end of the datas.
The format is : playerId::card1::card2::...::cardn||

Parameters
pPlayerThe data to convert
See also
datasplayer The data of the players
convertStructToString Do the same in the other direction
Returns
Return the datasplayer struct conversion of the players

Definition at line 168 of file cardgame.cpp.

References datasplayer::cardsList, and datasplayer::identifiant.

Referenced by main().

◆ convertStructToString()

string CardGameTools::convertStructToString ( datasplayer pPlayer)

Generate a data in a single line from the data of the player.

The separator in the string is the double of the character ":" . The real code is "::". The double code "||" define the end of the datas.
The format is : playerId::card1::card2::...::cardn||

Parameters
*pPlayerA pointer on the data to convert
See also
datasplayer The data of the players
convertStringToStuct Do the same in the other sense
Returns
Return the string conversion of the players

Definition at line 134 of file cardgame.cpp.

References datasplayer::cardsList, and datasplayer::identifiant.

Referenced by main().

◆ countGame()

int CardGameTools::countGame ( )

Read the game file and count the number of games.

Returns
the number of games

Definition at line 680 of file cardgame.cpp.

Referenced by gameRules().

◆ createGame()

datasgame * CardGameTools::createGame ( datasplayer vPlayer)

Create a game from the data of the player.

See also
datasgame
datasplayer
Parameters
vPlayer: The data of the player
Returns
the data game struct of the new created game

Definition at line 855 of file cardgame.cpp.

References datasplayer::actualCard, datasplayer::identifiant, datasplayer::isPlaying, loadAndMixCards(), datasgame::piocheCards, datasgame::playedCards, datasgame::playersList, datasplayer::points, and writeGame().

Referenced by gameRules().

◆ drawCardInPlay()

void CardGameTools::drawCardInPlay ( datasgame pGame)

Draw the cards in the table.

See also
datasgame
Parameters
pGame: All the data of the gcurrent game to display

Definition at line 1028 of file cardgame.cpp.

References datasgame::playedCards.

◆ drawCards()

void CardGameTools::drawCards ( vector< string > *  cardList)

Draw the cards list.

Parameters
cardList: The cards to display

Definition at line 914 of file cardgame.cpp.

Referenced by gameRules().

◆ drawInfos()

void CardGameTools::drawInfos ( datasplayer vPlayer)

Draw player informations.

See also
datasplayer
Parameters
vPlayer: The data of the current player to display

Definition at line 975 of file cardgame.cpp.

References datasplayer::identifiant.

Referenced by gameRules().

◆ drawPlayerCards()

void CardGameTools::drawPlayerCards ( datasplayer vPlayer)

Draw the cards of the player.

See also
datasplayer
Parameters
vPlayer: The data of the current player to display

Definition at line 1048 of file cardgame.cpp.

References datasplayer::cardsList, and datasplayer::isPlaying.

Referenced by gameRules().

◆ drawPlayers()

void CardGameTools::drawPlayers ( datasgame pGame)

Draw players game informations.

See also
datasgame
Parameters
pGame: All the data of the gcurrent game to display

Definition at line 995 of file cardgame.cpp.

References datasgame::playersList.

Referenced by gameRules().

◆ gameRules()

void CardGameTools::gameRules ( datasplayer vPlayer,
string *  action,
string *  card 
)

The rules Algorithm.

See also
datasplayer
Parameters
vPlayer: The data of the current player to display
action: Action of the human player
card: the card wanted

Definition at line 1279 of file cardgame.cpp.

References calculateCard(), datasplayer::cardsList, countGame(), createGame(), drawCards(), drawInfos(), drawPlayerCards(), drawPlayers(), getGame(), IAPlay(), datasplayer::identifiant, datasplayer::isPlaying, datasgame::piocheCards, playACard(), datasgame::playedCards, datasgame::playersList, datasplayer::points, testCard(), turnPlayers(), writeGame(), and writeWinner().

Referenced by main().

◆ generateUnicCookie()

string CardGameTools::generateUnicCookie ( )

generate an unique id

Returns
the id generated

Definition at line 659 of file cardgame.cpp.

Referenced by main().

◆ getFileGame()

string CardGameTools::getFileGame ( string  pName)

Get all game information from the name of the player.

read he game file and find the player for take all data of the player game

Parameters
pName: the name of the player
Returns
Return the data string structure of the game

Definition at line 288 of file cardgame.cpp.

Referenced by getGame().

◆ getGame()

datasgame * CardGameTools::getGame ( string  pName)

Convert the data to the datasgame struct.

Parameters
pName: the game data
Returns
Return the datasgame struct

Definition at line 326 of file cardgame.cpp.

References datasplayer::actualCard, datasplayer::cardsList, getFileGame(), datasplayer::identifiant, datasplayer::isPlaying, datasgame::piocheCards, datasgame::playedCards, datasgame::playersList, and datasplayer::points.

Referenced by gameRules().

◆ getNUMCookie()

string CardGameTools::getNUMCookie ( std::vector< HTTPCookie pCookieVector)

Get the cookie of the game from the list of the cookies

We select our personnal cookie in the list of cookies sended by the user.

Parameters
pCookieVector: the cookies list
See also
HTTPCookie
Returns
Return the id of the player

Definition at line 216 of file cardgame.cpp.

References cgicc::HTTPCookie::getName(), and cgicc::HTTPCookie::getValue().

Referenced by main().

◆ getValue()

string CardGameTools::getValue ( string  pName)

Get all personnal information from the cookie's Id.

read he session file and find the player for take all personnal information

Parameters
pName: the id of the player
Returns
Return the data string structure of the player

Definition at line 247 of file cardgame.cpp.

Referenced by main().

◆ IAPlay()

void CardGameTools::IAPlay ( datasgame readedGame,
int  pId 
)

AI algorithme for one AI player.

Simple AI:

  • If first in the game , He choose the first card in his cards list
  • Don't play without cards
  • Play the best card with the same color in the actual game
  • If no cards correspond, choose the first in the cards list
    See also
    datasgame
    Parameters
    readedGame: All the data of the gcurrent game to display
    pId: the id in the players list

Definition at line 1219 of file cardgame.cpp.

References playACard(), datasgame::playedCards, datasgame::playersList, and turnPlayers().

Referenced by gameRules().

◆ loadAndMixCards()

vector< string > * CardGameTools::loadAndMixCards ( )

Generate a mixed cards list.

Returns
the cards list

Definition at line 712 of file cardgame.cpp.

Referenced by createGame().

◆ playACard()

void CardGameTools::playACard ( datasplayer vPlayer,
datasgame readedGame,
string *  card 
)

The algorithm when a card is played.

When we choose a card , we need to add the card in a specific cards list and we need to extract the card from the player cards list Work only for AI players

See also
datasplayer
datasgame
Parameters
vPlayer: The data of the current player to display
readedGame: All the data of the gcurrent game to display
card: the played card

Definition at line 1084 of file cardgame.cpp.

References datasplayer::identifiant, datasgame::piocheCards, datasgame::playedCards, and datasgame::playersList.

Referenced by gameRules(), and IAPlay().

◆ testCard()

bool CardGameTools::testCard ( datasplayer vPlayer,
datasgame readedGame,
string *  card 
)

Test if the card is playable.

See also
datasplayer
datasgame
Parameters
vPlayer: The data of the current player to display
readedGame: All the data of the gcurrent game to display
card: the card wanted
Returns
True if it's good to play and false for others cases

Definition at line 1168 of file cardgame.cpp.

References datasplayer::identifiant, datasplayer::isPlaying, datasgame::playedCards, and datasgame::playersList.

Referenced by gameRules().

◆ turnPlayers()

void CardGameTools::turnPlayers ( datasplayer vPlayer,
datasgame readedGame 
)

Change the hand in the game.

The next candidate is to the right on the play table

See also
datasplayer
datasgame
Parameters
vPlayer: The data of the current player to display
readedGame: All the data of the gcurrent game to display

Definition at line 1133 of file cardgame.cpp.

References datasplayer::identifiant, datasplayer::isPlaying, and datasgame::playersList.

Referenced by gameRules(), and IAPlay().

◆ writeFileGame()

void CardGameTools::writeFileGame ( string  pName,
string  pValue 
)

Write data in the game file.

Parameters
pName: the name of the player
pValue: the value with game data

Definition at line 533 of file cardgame.cpp.

Referenced by main(), and writeGame().

◆ writeGame()

void CardGameTools::writeGame ( datasplayer pPlayer,
datasgame pGame 
)

Write datasgame struct in the game file.

Parameters
pPlayer: the data of the player
pGame: the data of the game

Definition at line 602 of file cardgame.cpp.

References datasplayer::actualCard, datasplayer::cardsList, datasplayer::identifiant, datasplayer::isPlaying, datasgame::piocheCards, datasgame::playedCards, datasgame::playersList, datasplayer::points, and writeFileGame().

Referenced by createGame(), and gameRules().

◆ writeValue()

void CardGameTools::writeValue ( string  pName,
string  pValue 
)

Write data in the cookie file.

Parameters
pName: the id of the player
pValue: the value with personnal data

Definition at line 516 of file cardgame.cpp.

Referenced by main().

◆ writeWinner()

void CardGameTools::writeWinner ( datasplayer vPlayer,
datasgame pGame 
)

Draw the winner informations.

See also
datasplayer
datasgame
Parameters
vPlayer: The data of the current player to display
pGame: All the data of the gcurrent game to display

Definition at line 935 of file cardgame.cpp.

References datasplayer::identifiant, and datasgame::playersList.

Referenced by gameRules().


GNU cgicc - A C++ class library for writing CGI applications
Copyright © 1996 - 2004 Stephen F. Booth
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front Cover Texts, and with no Back-Cover Texts.
Documentation generated Fri Mar 1 2024 08:39:42 for cgicc by doxygen 1.9.6