Rack: add a contains() convenience method

This commit is contained in:
Olivier Teulière 2013-01-17 17:58:56 +01:00
parent b493b3b365
commit 33214c62b2
4 changed files with 9 additions and 7 deletions

View file

@ -136,11 +136,11 @@ void BoardSearch::leftPart(Rack &iRack, Round &ioPartialWord,
if (iLimit > 0)
{
bool hasJokerInRack = iRack.count(Tile::Joker());
bool hasJokerInRack = iRack.contains(Tile::Joker());
for (unsigned int succ = m_dic.getSucc(n); succ; succ = m_dic.getNext(succ))
{
const Tile &l = Tile(m_dic.getChar(succ));
if (iRack.count(l))
if (iRack.contains(l))
{
iRack.remove(l);
ioPartialWord.addRightFromRack(l, false);
@ -182,13 +182,13 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord,
if (m_crossMx[iRow][iCol].isNone())
return;
bool hasJokerInRack = iRack.count(Tile::Joker());
bool hasJokerInRack = iRack.contains(Tile::Joker());
for (unsigned int succ = m_dic.getSucc(iNode); succ; succ = m_dic.getNext(succ))
{
const Tile &l = Tile(m_dic.getChar(succ));
if (m_crossMx[iRow][iCol].check(l))
{
if (iRack.count(l))
if (iRack.contains(l))
{
iRack.remove(l);
ioPartialWord.addRightFromRack(l, false);

View file

@ -270,7 +270,7 @@ int FreeGame::checkPass(const Player &iPlayer,
BOOST_FOREACH(wchar_t wch, iToChange)
{
// Remove the letter from the rack
if (!rack.count(Tile(wch)))
if (!rack.contains(Tile(wch)))
{
return 2;
}

View file

@ -497,7 +497,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
// We need to swap the joker (it is necessarily in the
// new tiles, because jokerAdded is true)
Rack tmpRack = pld.getNew();
ASSERT(tmpRack.count(Tile::Joker()), "No joker found in the new tiles");
ASSERT(tmpRack.contains(Tile::Joker()), "No joker found in the new tiles");
tmpRack.remove(Tile::Joker());
tmpRack.add(replacingTile);
pld.setNew(tmpRack);
@ -678,7 +678,7 @@ int Game::checkPlayedWord(const wstring &iCoord,
else
t = round.getTile(i);
if (!rack.count(t))
if (!rack.contains(t))
{
return 4;
}

View file

@ -45,6 +45,8 @@ public:
bool isEmpty() const { return getNbTiles() == 0; }
unsigned count(const Tile &t) const { return m_tiles[t.toCode()]; }
bool contains(const Tile &t) const { return count(t); }
void add(const Tile &t) { m_tiles[t.toCode()]++; m_nbTiles++; }
void remove(const Tile &t);
void clear();