Bag: the number of tiles cannot be negative

This commit is contained in:
Olivier Teulière 2013-01-17 17:21:33 +01:00
parent 3caacd9c84
commit bfcc7a80c6
2 changed files with 10 additions and 10 deletions

View file

@ -43,7 +43,7 @@ Bag::Bag(const Dictionary &iDic)
}
unsigned int Bag::count(const Tile &iTile) const
unsigned Bag::count(const Tile &iTile) const
{
map<Tile, int>::const_iterator it = m_tilesMap.find(iTile);
if (it != m_tilesMap.end())
@ -52,7 +52,7 @@ unsigned int Bag::count(const Tile &iTile) const
}
unsigned int Bag::getNbVowels() const
unsigned Bag::getNbVowels() const
{
int v = 0;
@ -66,7 +66,7 @@ unsigned int Bag::getNbVowels() const
}
unsigned int Bag::getNbConsonants() const
unsigned Bag::getNbConsonants() const
{
int c = 0;
@ -118,7 +118,7 @@ Tile Bag::selectRandomConsonant() const
}
Tile Bag::selectRandomTile(unsigned int total,
Tile Bag::selectRandomTile(unsigned total,
bool onlyVowels, bool onlyConsonants) const
{
ASSERT(total > 0, "Not enough tiles (of the requested kind) in the bag");

View file

@ -46,16 +46,16 @@ public:
void replaceTile(const Tile &iTile);
/// Count how many tiles identical to iTile are available in the bag
unsigned int count(const Tile &iTile) const;
unsigned count(const Tile &iTile) const;
/**
* Return how many tiles/vowels/consonants are available
* Warning: b.getNbVowels() + b.getNbConsonants() != b.getNbTiles(),
* because of the jokers and the 'Y'.
*/
unsigned int getNbTiles() const { return m_nbTiles; }
unsigned int getNbVowels() const;
unsigned int getNbConsonants() const;
unsigned getNbTiles() const { return m_nbTiles; }
unsigned getNbVowels() const;
unsigned getNbConsonants() const;
/**
* Return a random available tile
@ -88,10 +88,10 @@ private:
map<Tile, int> m_tilesMap;
/// Total number of tiles in the bag
int m_nbTiles;
unsigned m_nbTiles;
/// Helper method, used by the various selectRandom*() methods
Tile selectRandomTile(unsigned int total,
Tile selectRandomTile(unsigned total,
bool onlyVowels, bool onlyConsonants) const;
};