- correct bug in Game::back

- add regression test for this case
This commit is contained in:
Antoine Fraboulet 2005-12-27 01:06:54 +00:00
parent 8e93c14f92
commit fc157bc08f
3 changed files with 27 additions and 6 deletions

View file

@ -417,17 +417,20 @@ int Game::back(int n)
int i, j;
Player *player;
if (n < 0)
{
debug("Game::back negative argument\n");
n = -n;
}
debug("Game::back %d\n",n);
for (i = 0; i < n; i++)
{
if (m_history.getSize())
if (m_history.getSize() > 0)
{
prevPlayer();
player = m_players[m_currPlayer];
const Round &lastround = m_history.getPreviousTurn().getRound();
/* Remove the points of this round */
player->addPoints(- lastround.getPoints());
m_points -= lastround.getPoints();
debug("Game::back last round %s\n",lastround.toString().c_str());
/* Remove the word from the board, and put its letters back
* into the bag */
m_board.removeRound(*m_dic, lastround);
@ -441,7 +444,11 @@ int Game::back(int n)
m_bag.replaceTile(lastround.getTile(j));
}
}
delete &lastround;
/* Remove the points of this round */
player->addPoints(- lastround.getPoints());
m_points -= lastround.getPoints();
/* Remove the turns */
player->removeLastTurn();
m_history.removeLastTurn();
}
else
@ -841,3 +848,11 @@ int Game::checkPlayedWord(const string &iCoord,
return 0;
}
/****************************************************************/
/****************************************************************/
/// Local Variables:
/// mode: c++
/// mode: hs-minor
/// c-basic-offset: 4
/// End:

View file

@ -71,6 +71,10 @@ void Player::endTurn(const Round &iRound, int iTurn)
m_history.playRound(m_id,iTurn,iRound);
}
void Player::removeLastTurn()
{
m_history.removeLastTurn();
}
const string Player::toString() const
{

View file

@ -54,6 +54,8 @@ public:
void setCurrentRack(const PlayedRack &iPld);
const History& getHistory() const { return m_history; }
/// Remove last turn
void removeLastTurn();
/**************************
* Acessors for the score of the player