Bag: add a contains() convenience method

This commit is contained in:
Olivier Teulière 2013-01-17 17:33:19 +01:00
parent bfcc7a80c6
commit a13f7d2968
4 changed files with 11 additions and 5 deletions

View file

@ -82,7 +82,7 @@ unsigned Bag::getNbConsonants() const
void Bag::takeTile(const Tile &iTile)
{
ASSERT(count(iTile),
ASSERT(contains(iTile),
"The bag does not contain the letter " + lfw(iTile.getDisplayStr()));
m_tilesMap[iTile]--;

View file

@ -48,6 +48,12 @@ public:
/// Count how many tiles identical to iTile are available in the bag
unsigned count(const Tile &iTile) const;
/**
* Return true if the bag contains the given letter.
* This is a shortcut for: count(iTile) != 0
*/
bool contains(const Tile &iTile) const { return count(iTile); }
/**
* Return how many tiles/vowels/consonants are available
* Warning: b.getNbVowels() + b.getNbConsonants() != b.getNbTiles(),

View file

@ -111,7 +111,7 @@ void GameMoveCmd::playRound()
{
// Is the represented letter still available in the bag?
const Tile &t = m_round.getTile(i).toUpper();
if (bag.count(t))
if (bag.contains(t))
{
bag.replaceTile(Tile::Joker());
bag.takeTile(t);

View file

@ -348,7 +348,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
}
// 2) If there was no joker, we add one if possible
if (!jokerFound && bag.count(Tile::Joker()))
if (!jokerFound && bag.contains(Tile::Joker()))
{
jokerAdded = true;
pld.addNew(Tile::Joker());
@ -356,7 +356,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
}
// 3) Remove all the jokers from the bag, to avoid taking another one
while (bag.count(Tile::Joker()))
while (bag.contains(Tile::Joker()))
{
bag.takeTile(Tile::Joker());
}
@ -491,7 +491,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
// If the bag does not contain the letter anymore,
// simply keep the joker in the rack.
if (bag.count(replacingTile))
if (bag.contains(replacingTile))
{
// The bag contains the replacing letter
// We need to swap the joker (it is necessarily in the