Game Class Reference

#include <game.h>

Inheritance diagram for Game:

Duplicate FreeGame Training

Detailed Description

Parent class of all the Game types.

It offers the common attributes (Board, Bag, etc...) as well as useful "helper" methods to factorize some code.

Definition at line 51 of file game.h.

Public Types

enum  GameMode { kTRAINING, kFREEGAME, kDUPLICATE }
 Game mode: each one of these modes is implemented in an inherited class. More...
enum  GameVariant { kNONE, kJOKER }
 Game variant: it slightly modifies the rules of the game. More...
enum  game_file_format { FILE_FORMAT_STANDARD, FILE_FORMAT_ADVANCED }
 Eliot file formats. More...
enum  set_rack_mode { RACK_ALL, RACK_NEW, RACK_MANUAL }

Public Member Functions

 Game (const Dictionary &iDic)
virtual ~Game ()
virtual GameMode getMode () const =0
virtual string getModeAsString () const =0
void setVariant (GameVariant iVariant)
 Accessors for the variant of the game.
GameVariant getVariant () const
const DictionarygetDic () const
 Dictionary associated with the game.
void setDic (const Dictionary &iDic)
const BoardgetBoard () const
const BaggetBag () const
const PlayergetPlayer (int iNum) const
const TurngetTurn (int iNum) const
const PlayergetCurrentPlayer () const
void save (ostream &out, game_file_format format=FILE_FORMAT_STANDARD) const
 Save a game to a File Standard format is used for training games so that it is compatible with previous versions of Eliot.
int back (int)
int setRack (int player, set_rack_mode mode, bool check, const string &str)
string getPlayerRack (int, PlayedRack::display_mode mode=PlayedRack::RACK_SIMPLE) const
const HistorygetHistory () const
 Methods to access already played words.
int getNPlayers () const
 Methods to access players.
int getNHumanPlayers () const
virtual void addHumanPlayer ()
virtual void addAIPlayer ()
int currPlayer () const
virtual int start ()=0
 Game handling.
virtual int play (const string &iCoord, const string &iWord)=0
virtual int endTurn ()=0

Static Public Member Functions

static Gameload (FILE *fin, const Dictionary &iDic)
 Saved games handling.

Static Public Attributes

static const int RACK_SIZE = 7

Protected Member Functions

int helperPlayRound (const Round &iRound)
int helperSetRackRandom (int p, bool iCheck, set_rack_mode mode)
int helperSetRackManual (int p, bool iCheck, const string &iLetters)
void prevPlayer ()
void nextPlayer ()
bool rackInBag (const Rack &iRack, const Bag &iBag) const
void realBag (Bag &iBag) const
int checkPlayedWord (const string &iCoord, const string &iWord, Round &oRound)
void gameSaveFormat_14 (ostream &out) const
 Training games ares saved using the initial Eliot format.
void gameSaveFormat_15 (ostream &out) const
 Advanced game file format output.

Static Protected Member Functions

static GamegameLoadFormat_14 (FILE *fin, const Dictionary &iDic)
 load games from File using the first format.
static GamegameLoadFormat_15 (FILE *fin, const Dictionary &iDic)
 load games from File using advanced format (since Eliot 1.5) This format is used for Duplicate, Freegame, .

Protected Attributes

vector< Player * > m_players
 All the players, indexed by their ID.
int m_currPlayer
 ID of the "current" player.
GameVariant m_variant
 Variant.
const Dictionarym_dic
 Dictionary currently associated to the game.
Bag m_bag
 Bag.
Board m_board
 Board.
History m_history
 History of the game.
int m_points
bool m_finished


Member Enumeration Documentation

enum Game::game_file_format
 

Eliot file formats.

Enumerator:
FILE_FORMAT_STANDARD 
FILE_FORMAT_ADVANCED 

Definition at line 98 of file game.h.

enum Game::GameMode
 

Game mode: each one of these modes is implemented in an inherited class.

Enumerator:
kTRAINING 
kFREEGAME 
kDUPLICATE 

Definition at line 58 of file game.h.

enum Game::GameVariant
 

Game variant: it slightly modifies the rules of the game.

Enumerator:
kNONE 
kJOKER 

Definition at line 68 of file game.h.

enum Game::set_rack_mode
 

Enumerator:
RACK_ALL 
RACK_NEW 
RACK_MANUAL 

Definition at line 145 of file game.h.


Constructor & Destructor Documentation

Game::Game const Dictionary iDic  ) 
 

Definition at line 40 of file game.cpp.

References kNONE, m_currPlayer, m_finished, m_points, and m_variant.

Game::~Game  )  [virtual]
 

Definition at line 50 of file game.cpp.

References getNPlayers(), and m_players.


Member Function Documentation

void Game::addAIPlayer  )  [virtual]
 

Reimplemented in Training.

Definition at line 474 of file game.cpp.

References getNPlayers(), and m_players.

Referenced by GameFactory::createFromCmdLine(), gameLoadFormat_15(), and main_loop().

void Game::addHumanPlayer  )  [virtual]
 

Reimplemented in Training.

Definition at line 467 of file game.cpp.

References getNPlayers(), and m_players.

Referenced by GameFactory::createFromCmdLine(), gameLoadFormat_15(), main_loop(), and Training::start().

int Game::back int   ) 
 

Definition at line 152 of file game.cpp.

References Player::addPoints(), debug, Round::getPoints(), History::getPreviousTurn(), Turn::getRound(), History::getSize(), Round::getTile(), Round::getWordLen(), Round::isJoker(), Round::isPlayedFromRack(), Tile::Joker(), m_bag, m_board, m_currPlayer, m_dic, m_history, m_players, m_points, prevPlayer(), History::removeLastTurn(), Player::removeLastTurn(), Board::removeRound(), Bag::replaceTile(), and Round::toString().

Referenced by loop_training().

int Game::checkPlayedWord const string &  iCoord,
const string &  iWord,
Round oRound
[protected]
 

Definition at line 520 of file game.cpp.

References Round::accessCoord(), ASSERT, Dic_search_word(), Round::getCoord(), getNPlayers(), Round::init(), Coord::isValid(), m_dic, and Coord::setFromString().

Referenced by Training::play(), FreeGame::play(), and Duplicate::play().

int Game::currPlayer  )  const [inline]
 

Definition at line 164 of file game.h.

References m_currPlayer.

Referenced by display_data(), getCurrentPlayer(), loop_freegame(), and GameIO::printPlayedRack().

virtual int Game::endTurn  )  [pure virtual]
 

Implemented in Duplicate, FreeGame, and Training.

Game * Game::gameLoadFormat_14 FILE *  fin,
const Dictionary iDic
[static, protected]
 

load games from File using the first format.

This format is used for Training games

Definition at line 97 of file game_io.cpp.

References GameFactory::createTraining(), debug, GameFactory::Instance(), play(), RACK_MANUAL, and start().

Referenced by load().

Game * Game::gameLoadFormat_15 FILE *  fin,
const Dictionary iDic
[static, protected]
 

load games from File using advanced format (since Eliot 1.5) This format is used for Duplicate, Freegame, .

..

Definition at line 173 of file game_io.cpp.

References addAIPlayer(), addHumanPlayer(), PlayedRack::addNew(), PlayedRack::addOld(), Round::addRightFromBoard(), Round::addRightFromRack(), GameFactory::createDuplicate(), GameFactory::createFreeGame(), GameFactory::createTraining(), getMode(), getNPlayers(), Board::getTile(), GameFactory::Instance(), Tile::Joker(), kTRAINING, m_bag, m_board, m_players, Round::setBonus(), Round::setPoints(), Bag::takeTile(), and Coord::VERTICAL.

Referenced by load().

void Game::gameSaveFormat_14 ostream &  out  )  const [protected]
 

Training games ares saved using the initial Eliot format.

Definition at line 408 of file game_io.cpp.

References Coord::COORD_MODE_LONG, getCurrentPlayer(), Turn::getPlayedRack(), History::getSize(), History::getTurn(), IDENT_STRING, m_history, PlayedRack::RACK_EXTRA, and PlayedRack::toString().

Referenced by save().

void Game::gameSaveFormat_15 ostream &  out  )  const [protected]
 

Advanced game file format output.

Definition at line 443 of file game_io.cpp.

References getModeAsString(), getNPlayers(), Turn::getRound(), History::getSize(), History::getTurn(), Round::getWord(), IDENT_FORMAT_15, IDENT_STRING, m_history, and m_players.

Referenced by save().

const Bag& Game::getBag  )  const [inline]
 

Definition at line 90 of file game.h.

References m_bag.

Referenced by GameIO::printNonPlayed(), and BagFrame::Refresh().

const Board& Game::getBoard  )  const [inline]
 

Definition at line 89 of file game.h.

References m_board.

Referenced by GameIO::printBoard(), GameIO::printBoardJoker(), GameIO::printBoardMultipliers(), and GameIO::printBoardMultipliers2().

const Player& Game::getCurrentPlayer  )  const [inline]
 

Definition at line 93 of file game.h.

References currPlayer(), and getPlayer().

Referenced by gameSaveFormat_14(), helperPlayRound(), GfxResult::Refresh(), and Plus1Frame::refresh().

const Dictionary& Game::getDic  )  const [inline]
 

Dictionary associated with the game.

The dictionary can be changed during a game without problem

Definition at line 86 of file game.h.

References m_dic.

Referenced by loop_duplicate(), loop_freegame(), loop_training(), RaccFrame::refresh(), BenjFrame::refresh(), Plus1Frame::refresh(), and AuxFrameList::Refresh().

const History& Game::getHistory  )  const [inline]
 

Methods to access already played words.

The int parameter should be 0 <= int < getNTurns()

Definition at line 153 of file game.h.

References m_history.

Referenced by GamePrintout::DrawPage(), and GameFrame::Refresh().

virtual GameMode Game::getMode  )  const [pure virtual]
 

Implemented in Duplicate, FreeGame, and Training.

Referenced by gameLoadFormat_15(), main_loop(), realBag(), RaccFrame::refresh(), BenjFrame::refresh(), and save().

virtual string Game::getModeAsString  )  const [pure virtual]
 

Implemented in Duplicate, FreeGame, and Training.

Referenced by gameSaveFormat_15().

int Game::getNHumanPlayers  )  const
 

Definition at line 458 of file game.cpp.

References getNPlayers(), getPlayer(), and Player::isHuman().

Referenced by Duplicate::nextHumanPlayer(), and Duplicate::prevHumanPlayer().

int Game::getNPlayers  )  const [inline]
 

Methods to access players.

The int parameter should be 0 <= int < getNPlayers()

Definition at line 159 of file game.h.

References m_players.

Referenced by addAIPlayer(), addHumanPlayer(), checkPlayedWord(), Duplicate::endTurn(), gameLoadFormat_15(), gameSaveFormat_15(), getNHumanPlayers(), helperSetRackRandom(), nextPlayer(), prevPlayer(), GameIO::printAllPoints(), GameIO::printAllRacks(), realBag(), Duplicate::setPlayer(), Training::start(), FreeGame::start(), and ~Game().

const Player & Game::getPlayer int  iNum  )  const
 

Definition at line 59 of file game.cpp.

References ASSERT, and m_players.

Referenced by getCurrentPlayer(), getNHumanPlayers(), getPlayerRack(), helperPlayRound(), helperSetRackManual(), helperSetRackRandom(), GameIO::printAllPoints(), GameIO::printPoints(), realBag(), and GameFrame::Refresh().

string Game::getPlayerRack int  ,
PlayedRack::display_mode  mode = PlayedRack::RACK_SIMPLE
const
 

Definition at line 452 of file game.cpp.

References Player::getCurrentRack(), getPlayer(), and PlayedRack::toString().

Referenced by GameIO::printAllRacks(), and GameIO::printPlayedRack().

const Turn& Game::getTurn int  iNum  )  const
 

GameVariant Game::getVariant  )  const [inline]
 

Definition at line 80 of file game.h.

References m_variant.

int Game::helperPlayRound const Round iRound  )  [protected]
 

Definition at line 67 of file game.cpp.

References PlayedRack::getAllTiles(), getCurrentPlayer(), Player::getCurrentRack(), Player::getLastRack(), getPlayer(), Round::getPoints(), History::getSize(), Round::getTile(), Round::getWordLen(), Round::isJoker(), Round::isPlayedFromRack(), kJOKER, m_currPlayer, m_history, m_points, m_variant, History::playRound(), realBag(), Bag::replaceTile(), History::setCurrentRack(), and Tile::toChar().

Referenced by Training::play(), FreeGame::play(), and Training::playResult().

int Game::helperSetRackManual int  p,
bool  iCheck,
const string &  iLetters
[protected]
 

Definition at line 389 of file game.cpp.

References PlayedRack::addOld(), Player::getCurrentRack(), getPlayer(), and PlayedRack::reset().

int Game::helperSetRackRandom int  p,
bool  iCheck,
set_rack_mode  mode
[protected]
 

Definition at line 249 of file game.cpp.

References ASSERT, Player::getCurrentRack(), PlayedRack::getNewTiles(), getNPlayers(), getPlayer(), PlayedRack::nOld(), RACK_NEW, realBag(), Bag::replaceTile(), and PlayedRack::resetNew().

Referenced by Training::setRackRandom(), FreeGame::setRackRandom(), and Duplicate::setRackRandom().

Game * Game::load FILE *  fin,
const Dictionary iDic
[static]
 

Saved games handling.

load() returns the loaded game, or NULL if there was a problem load() might need some more work to be robust enough to handle "hand written" files

Definition at line 52 of file game_io.cpp.

References debug, gameLoadFormat_14(), gameLoadFormat_15(), IDENT_FORMAT_15, and IDENT_STRING.

Referenced by main_loop().

void Game::nextPlayer  )  [protected]
 

Definition at line 491 of file game.cpp.

References ASSERT, getNPlayers(), and m_currPlayer.

Referenced by FreeGame::endTurn(), and Duplicate::nextHumanPlayer().

virtual int Game::play const string &  iCoord,
const string &  iWord
[pure virtual]
 

Implemented in Duplicate, FreeGame, and Training.

Referenced by gameLoadFormat_14().

void Game::prevPlayer  )  [protected]
 

Definition at line 480 of file game.cpp.

References ASSERT, getNPlayers(), and m_currPlayer.

Referenced by back(), and Duplicate::prevHumanPlayer().

bool Game::rackInBag const Rack iRack,
const Bag iBag
const [protected]
 

Definition at line 236 of file game.cpp.

References Tile::getAllTiles(), Bag::in(), and Rack::in().

void Game::realBag Bag iBag  )  const [protected]
 

Definition at line 203 of file game.cpp.

References PlayedRack::getAllTiles(), Player::getCurrentRack(), getMode(), getNPlayers(), getPlayer(), kFREEGAME, m_bag, and Bag::takeTile().

Referenced by helperPlayRound(), and helperSetRackRandom().

void Game::save ostream &  out,
game_file_format  format = FILE_FORMAT_STANDARD
const
 

Save a game to a File Standard format is used for training games so that it is compatible with previous versions of Eliot.

Saving can be forced to advanced format for training games by setting the last parameter to FILE_FORMAT_ADVANCED

Definition at line 395 of file game_io.cpp.

References FILE_FORMAT_STANDARD, gameSaveFormat_14(), gameSaveFormat_15(), getMode(), and kTRAINING.

Referenced by display_data(), loop_duplicate(), loop_freegame(), loop_training(), and GameFrame::Refresh().

void Game::setDic const Dictionary iDic  )  [inline]
 

Definition at line 87 of file game.h.

References m_dic.

int Game::setRack int  player,
set_rack_mode  mode,
bool  check,
const string &  str
 

void Game::setVariant GameVariant  iVariant  )  [inline]
 

Accessors for the variant of the game.

The variant can be changed during a game without any problem (though it seems rather useless...)

Definition at line 79 of file game.h.

References m_variant.

Referenced by GameFactory::createFromCmdLine().

virtual int Game::start  )  [pure virtual]
 

Game handling.

Implemented in Duplicate, FreeGame, and Training.

Referenced by gameLoadFormat_14(), main(), and MainFrame::OnMenuGameNew().


Field Documentation

Bag Game::m_bag [protected]
 

Bag.

Definition at line 189 of file game.h.

Referenced by back(), gameLoadFormat_15(), getBag(), and realBag().

Board Game::m_board [protected]
 

Board.

Definition at line 192 of file game.h.

Referenced by back(), gameLoadFormat_15(), getBoard(), Training::removeTestPlay(), Training::search(), and Training::testPlay().

int Game::m_currPlayer [protected]
 

ID of the "current" player.

Definition at line 177 of file game.h.

Referenced by back(), currPlayer(), FreeGame::endTurn(), Duplicate::endTurn(), Game(), helperPlayRound(), Duplicate::nextHumanPlayer(), nextPlayer(), Training::play(), FreeGame::play(), Duplicate::play(), Training::playResult(), Duplicate::prevHumanPlayer(), prevPlayer(), Training::search(), Duplicate::setPlayer(), Training::setRack(), Training::setRackManual(), Training::start(), and FreeGame::start().

const Dictionary* Game::m_dic [protected]
 

Dictionary currently associated to the game.

Definition at line 186 of file game.h.

Referenced by back(), checkPlayedWord(), getDic(), Training::search(), and setDic().

bool Game::m_finished [protected]
 

Definition at line 202 of file game.h.

Referenced by Game(), and FreeGame::pass().

History Game::m_history [protected]
 

History of the game.

The vector is indexed by the number of turns in the game

Definition at line 198 of file game.h.

Referenced by back(), gameSaveFormat_14(), gameSaveFormat_15(), getHistory(), helperPlayRound(), Training::play(), FreeGame::play(), Training::playResult(), and Training::search().

vector<Player*> Game::m_players [protected]
 

All the players, indexed by their ID.

Definition at line 175 of file game.h.

Referenced by addAIPlayer(), addHumanPlayer(), back(), FreeGame::endTurn(), Duplicate::endTurn(), gameLoadFormat_15(), gameSaveFormat_15(), getNPlayers(), getPlayer(), Duplicate::nextHumanPlayer(), Training::play(), FreeGame::play(), Training::playResult(), Duplicate::prevHumanPlayer(), Training::search(), Duplicate::setPlayer(), FreeGame::start(), and ~Game().

int Game::m_points [protected]
 

Definition at line 200 of file game.h.

Referenced by back(), Game(), and helperPlayRound().

GameVariant Game::m_variant [protected]
 

Variant.

Definition at line 183 of file game.h.

Referenced by Game(), getVariant(), helperPlayRound(), and setVariant().

const int Game::RACK_SIZE = 7 [static]
 

Definition at line 144 of file game.h.


The documentation for this class was generated from the following files:
Generated on Thu Dec 29 02:01:15 2005 for Eliot by  doxygen 1.4.5