Minor API enhancements

This commit is contained in:
Olivier Teulière 2005-02-09 22:33:56 +00:00
parent 104335e6aa
commit d41530c496
9 changed files with 48 additions and 35 deletions

View file

@ -2,7 +2,7 @@
* Copyright (C) 2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: duplicate.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: duplicate.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -116,13 +116,13 @@ int Duplicate::start()
return 1;
}
PlayedRack &pld = m_players[m_currPlayer]->getPlayedRack();
PlayedRack pld = m_players[m_currPlayer]->getCurrentRack();
/* All the players have the same rack */
for (i = 0; i < getNPlayers(); i++)
{
if (i != m_currPlayer)
{
m_players[i]->getPlayedRack() = pld;
m_players[i]->setCurrentRack(pld);
}
/* Nobody has played yet in this round */
m_players[i]->setStatus(Player::TO_PLAY);
@ -234,13 +234,13 @@ int Duplicate::endTurnForReal()
return 1;
}
PlayedRack &pld = m_players[imax]->getPlayedRack();
PlayedRack pld = m_players[imax]->getCurrentRack();
/* All the players have the same rack */
for (i = 0; i < getNPlayers(); i++)
{
if (i != imax)
{
m_players[i]->getPlayedRack() = pld;
m_players[i]->setCurrentRack(pld);
}
/* Nobody has played yet in this round */
m_players[i]->setStatus(Player::TO_PLAY);

View file

@ -2,7 +2,7 @@
* Copyright (C) 2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: duplicate.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: duplicate.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,6 +41,7 @@ public:
virtual ~Duplicate();
virtual GameMode getMode() const { return kDUPLICATE; }
virtual string getModeAsString() const { return "Duplicate"; }
/*************************
* Game handling

View file

@ -2,7 +2,7 @@
* Copyright (C) 2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: freegame.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: freegame.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -175,7 +175,7 @@ void FreeGame::end()
{
if (i != m_currPlayer)
{
PlayedRack &pld = m_players[i]->getPlayedRack();
const PlayedRack &pld = m_players[i]->getCurrentRack();
pld.getAllTiles(tiles);
for (unsigned int j = 0; j < tiles.size(); j++)
{
@ -205,7 +205,7 @@ int FreeGame::pass(const string &iToChange, int n)
return 1;
}
PlayedRack &pld = player->getPlayedRack();
PlayedRack pld = player->getCurrentRack();
Rack rack;
pld.getRack(rack);
@ -227,6 +227,8 @@ int FreeGame::pass(const string &iToChange, int n)
pld.reset();
pld.setOld(rack);
player->setCurrentRack(pld);
// FIXME: the letters to change should not be in the bag while generating
// the new rack!

View file

@ -2,7 +2,7 @@
* Copyright (C) 2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: freegame.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: freegame.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -41,6 +41,7 @@ public:
virtual ~FreeGame();
virtual GameMode getMode() const { return kFREEGAME; }
virtual string getModeAsString() const { return "Free game"; }
/*************************
* Game handling

View file

@ -3,7 +3,7 @@
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
* Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: game.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: game.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -171,7 +171,7 @@ Game * Game::load(FILE *fin, const Dictionary &iDic)
}
// Give the rack to the player
pGame->m_players[nb]->getPlayedRack() = pldrack;
pGame->m_players[nb]->setCurrentRack(pldrack);
}
// Read next line
continue;
@ -273,7 +273,7 @@ Game * Game::load(FILE *fin, const Dictionary &iDic)
pGame->m_currPlayer = player;
// Update the rack for the player
pGame->m_players[player]->getPlayedRack() = pldrack;
pGame->m_players[player]->setCurrentRack(pldrack);
// End the turn for the current player (this creates a new rack)
pGame->m_players[player]->endTurn(round, num - 1);
// Add the points
@ -299,13 +299,7 @@ void Game::save(ostream &out) const
const string decal = " ";
// "Header" of the game
out << IDENT_STRING << endl << endl;
out << "Game type: ";
if (getMode() == kTRAINING)
out << "Training" << endl;
else if (getMode() == kDUPLICATE)
out << "Duplicate" << endl;
else
out << "Free game" << endl;
out << "Game type: " << getModeAsString();
for (int i = 0; i < getNPlayers(); i++)
{
out << "Player " << i << ": ";
@ -340,7 +334,7 @@ void Game::save(ostream &out) const
out << endl;
for (int i = 0; i < getNPlayers(); i++)
{
string rack = formatPlayedRack(m_players[i]->getPlayedRack());
string rack = formatPlayedRack(m_players[i]->getCurrentRack());
out << "Rack " << i << ": " << rack << endl;
}
}
@ -494,7 +488,7 @@ void Game::realBag(Bag &ioBag) const
/* In freegame mode, replace the letters from all the racks */
for (int i = 0; i < getNPlayers(); i++)
{
PlayedRack &pld = m_players[i]->getPlayedRack();
PlayedRack pld = m_players[i]->getCurrentRack();
pld.getAllTiles(tiles);
for (unsigned int j = 0; j < tiles.size(); j++)
{
@ -506,7 +500,7 @@ void Game::realBag(Bag &ioBag) const
{
/* In training or duplicate mode, replace the rack of the current
* player only */
PlayedRack &pld = m_players[m_currPlayer]->getPlayedRack();
PlayedRack pld = m_players[m_currPlayer]->getCurrentRack();
pld.getAllTiles(tiles);
for (int j = 0; j < pld.nTiles(); j++)
{
@ -537,7 +531,7 @@ int Game::helperSetRackRandom(int p, bool iCheck, set_rack_mode mode)
PDEBUG(p < 0 || p >= getNPlayers(), "GAME: wrong player number\n");
PlayedRack &pld = m_players[p]->getPlayedRack();
PlayedRack pld = m_players[p]->getCurrentRack();
nold = pld.nOld();
/* Create a copy of the bag in which we can do everything we want */
@ -617,6 +611,8 @@ int Game::helperSetRackRandom(int p, bool iCheck, set_rack_mode mode)
if (iCheck && !pld.checkRack(min))
return 2;
m_players[p]->setCurrentRack(pld);
return 0;
}
@ -626,7 +622,7 @@ int Game::helperSetRackManual(int p, bool iCheck, const string &iLetters)
unsigned int i;
int min;
PlayedRack &pld = m_players[p]->getPlayedRack();
PlayedRack pld = m_players[p]->getCurrentRack();
m_players[p]->clearResults();
pld.reset();
@ -673,9 +669,12 @@ int Game::helperSetRackManual(int p, bool iCheck, const string &iLetters)
min = 2;
else
min = 1;
return pld.checkRack(min) ? 0 : 2;
if (!pld.checkRack(min))
return 2;
}
m_players[p]->setCurrentRack(pld);
return 0;
}
@ -852,7 +851,7 @@ string Game::getPlayerRack(int num) const
{
if (num < 0 || num >= getNPlayers())
return "";
return formatPlayedRack(m_players[num]->getPlayedRack(), false);
return formatPlayedRack(m_players[num]->getCurrentRack(), false);
}
@ -1003,7 +1002,7 @@ int Game::checkPlayedWord(const string &iCoord,
* one by one */
Rack rack;
Player *player = m_players[m_currPlayer];
player->getPlayedRack().getRack(rack);
player->getCurrentRack().getRack(rack);
for (int i = 0; i < oRound.getWordLen(); i++)
{

View file

@ -3,7 +3,7 @@
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
* Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: game.h,v 1.3 2005/02/05 11:14:56 ipkiss Exp $
* $Id: game.h,v 1.4 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -83,6 +83,7 @@ public:
kDUPLICATE
};
virtual GameMode getMode() const = 0;
virtual string getModeAsString() const = 0;
/*************************
* handling games

View file

@ -1,8 +1,8 @@
/*****************************************************************************
* Copyright (C) 1999-2005 Eliot
* Copyright (C) 2004-2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: player.cpp,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: player.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -48,12 +48,18 @@ Player::~Player()
}
PlayedRack & Player::getPlayedRack() const
const PlayedRack & Player::getCurrentRack() const
{
return *m_playedRacks.back();
}
void Player::setCurrentRack(const PlayedRack &iPld)
{
*m_playedRacks.back() = iPld;
}
const PlayedRack & Player::getLastRack() const
{
return *m_playedRacks[m_playedRacks.size() - 2];

View file

@ -2,7 +2,7 @@
* Copyright (C) 2004-2005 Eliot
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: player.h,v 1.2 2005/02/05 11:14:56 ipkiss Exp $
* $Id: player.h,v 1.3 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -40,10 +40,12 @@ public:
* General getters
**************************/
// FIXME: we should have a const getter!
PlayedRack & getPlayedRack() const;
const PlayedRack & getCurrentRack() const;
const PlayedRack & getLastRack() const;
const Round & getLastRound() const;
void setCurrentRack(const PlayedRack &iPld);
/**************************
* Add (or remove, if the given value is negative) points
* to the player's score.

View file

@ -3,7 +3,7 @@
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
* Olivier Teuliere <ipkiss@via.ecp.fr>
*
* $Id: training.h,v 1.1 2005/02/05 11:14:56 ipkiss Exp $
* $Id: training.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -42,6 +42,7 @@ public:
virtual ~Training();
virtual GameMode getMode() const { return kTRAINING; }
virtual string getModeAsString() const { return "Training"; }
/*************************
* Game handling