mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-18 10:26:15 +01:00
Added several assertions
This commit is contained in:
parent
32957abfcc
commit
66eec913c9
3 changed files with 32 additions and 1 deletions
|
@ -159,12 +159,18 @@ void Board::addRound(const Dictionary &iDic, const Round &iRound)
|
|||
{
|
||||
if (isVacant(row, col + i))
|
||||
{
|
||||
ASSERT(iRound.isPlayedFromRack(i), "Invalid round (1)");
|
||||
t = iRound.getTile(i);
|
||||
m_tilesRow[row][col + i] = t;
|
||||
m_jokerRow[row][col + i] = iRound.isJoker(i);
|
||||
m_tilesCol[col + i][row] = t;
|
||||
m_jokerCol[col + i][row] = iRound.isJoker(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(!iRound.isPlayedFromRack(i), "Invalid round (2)");
|
||||
ASSERT(t == m_tilesRow[row][col + i].toUpper(), "Invalid round (3)");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -174,12 +180,18 @@ void Board::addRound(const Dictionary &iDic, const Round &iRound)
|
|||
{
|
||||
if (isVacant(row + i, col))
|
||||
{
|
||||
ASSERT(iRound.isPlayedFromRack(i), "Invalid round (1)");
|
||||
t = iRound.getTile(i);
|
||||
m_tilesRow[row + i][col] = t;
|
||||
m_jokerRow[row + i][col] = iRound.isJoker(i);
|
||||
m_tilesCol[col][row + i] = t;
|
||||
m_jokerCol[col][row + i] = iRound.isJoker(i);
|
||||
}
|
||||
else
|
||||
{
|
||||
ASSERT(!iRound.isPlayedFromRack(i), "Invalid round (2)");
|
||||
ASSERT(t == m_tilesRow[row + i][col].toUpper(), "Invalid round (3)");
|
||||
}
|
||||
}
|
||||
}
|
||||
buildCross(iDic);
|
||||
|
@ -206,6 +218,8 @@ void Board::removeRound(const Dictionary &iDic, const Round &iRound)
|
|||
"Invalid round removal");
|
||||
if (iRound.isPlayedFromRack(i))
|
||||
{
|
||||
ASSERT(iRound.isJoker(i) == m_jokerRow[row][col + i],
|
||||
"Invalid round removal");
|
||||
m_tilesRow[row][col + i] = Tile();
|
||||
m_jokerRow[row][col + i] = false;
|
||||
m_crossRow[row][col + i].setAny();
|
||||
|
@ -223,6 +237,8 @@ void Board::removeRound(const Dictionary &iDic, const Round &iRound)
|
|||
"Invalid round removal");
|
||||
if (iRound.isPlayedFromRack(i))
|
||||
{
|
||||
ASSERT(iRound.isJoker(i) == m_jokerRow[row + i][col],
|
||||
"Invalid round removal");
|
||||
m_tilesRow[row + i][col] = Tile();
|
||||
m_jokerRow[row + i][col] = false;
|
||||
m_crossRow[row + i][col].setAny();
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include "tile.h"
|
||||
#include "round.h"
|
||||
#include "encoding.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, Round);
|
||||
|
@ -45,32 +46,44 @@ void Round::setWord(const vector<Tile> &iTiles)
|
|||
}
|
||||
|
||||
|
||||
void Round::setTile(unsigned int iIndex, const Tile &iTile)
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
m_word[iIndex] = iTile;
|
||||
}
|
||||
|
||||
|
||||
void Round::setFromRack(unsigned int iIndex)
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
m_rackOrigin[iIndex] = true;
|
||||
}
|
||||
|
||||
|
||||
void Round::setFromBoard(unsigned int iIndex)
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
m_rackOrigin[iIndex] = false;
|
||||
}
|
||||
|
||||
|
||||
bool Round::isJoker(unsigned int iIndex) const
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
return m_word[iIndex].isJoker();
|
||||
}
|
||||
|
||||
|
||||
const Tile& Round::getTile(unsigned int iIndex) const
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
return m_word[iIndex];
|
||||
}
|
||||
|
||||
|
||||
bool Round::isPlayedFromRack(unsigned int iIndex) const
|
||||
{
|
||||
ASSERT(iIndex < m_word.size(), "Invalid index");
|
||||
return m_rackOrigin[iIndex];
|
||||
}
|
||||
|
||||
|
@ -96,6 +109,8 @@ void Round::addRightFromRack(const Tile &iTile, bool iJoker)
|
|||
|
||||
void Round::removeRight()
|
||||
{
|
||||
ASSERT(!m_word.empty() && !m_rackOrigin.empty(),
|
||||
"Trying to remove tiles that were never added");
|
||||
m_word.pop_back();
|
||||
m_rackOrigin.pop_back();
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
*************************/
|
||||
void setPoints(int iPoints) { m_points = iPoints; }
|
||||
void setBonus(bool iBonus) { m_bonus = iBonus; }
|
||||
void setTile(unsigned int iIndex, const Tile &iTile) { m_word[iIndex] = iTile; }
|
||||
void setTile(unsigned int iIndex, const Tile &iTile);
|
||||
void setWord(const vector<Tile> &iTiles);
|
||||
void setFromRack(unsigned int iIndex);
|
||||
void setFromBoard(unsigned int iIndex);
|
||||
|
|
Loading…
Reference in a new issue