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

## 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.

## ◆ 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

  pPlayer | The 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.

## ◆ 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

  *pPlayer | A 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.

## ◆ 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().

## ◆ 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.

## ◆ 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.

## ◆ 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.

## ◆ 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.

## ◆ 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 countGame(), getGame(), and datasplayer::identifiant.

## ◆ 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().

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(), and cgicc::FormEntry::operator*().

## ◆ 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().

## ◆ 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 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.

## ◆ 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 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 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().

## ◆ 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.

## ◆ 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.