Bag: rename a method

This commit is contained in:
Olivier Teulière 2013-01-17 17:14:38 +01:00
parent 652ee671de
commit c1c3f3b48b
9 changed files with 18 additions and 18 deletions

View file

@ -45,7 +45,7 @@ Bag::Bag(const Dictionary &iDic)
}
unsigned int Bag::in(const Tile &iTile) const
unsigned int Bag::count(const Tile &iTile) const
{
map<Tile, int>::const_iterator it = m_tilesMap.find(iTile);
if (it != m_tilesMap.end())
@ -84,7 +84,7 @@ unsigned int Bag::getNbConsonants() const
void Bag::takeTile(const Tile &iTile)
{
ASSERT(in(iTile),
ASSERT(count(iTile),
"The bag does not contain the letter " + lfw(iTile.getDisplayStr()));
m_tilesMap[iTile]--;
@ -94,7 +94,7 @@ void Bag::takeTile(const Tile &iTile)
void Bag::replaceTile(const Tile &iTile)
{
ASSERT(in(iTile) < iTile.maxNumber(),
ASSERT(count(iTile) < iTile.maxNumber(),
"Cannot replace tile: " + lfw(iTile.getDisplayStr()));
m_tilesMap[iTile]++;

View file

@ -45,8 +45,8 @@ public:
/// Replace a tile into the bag
void replaceTile(const Tile &iTile);
/// Return how many tiles identical to iTile are available in the bag
unsigned int in(const Tile &iTile) const;
/// Count how many tiles identical to iTile are available in the bag
unsigned int count(const Tile &iTile) const;
/**
* Return how many tiles/vowels/consonants are available

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.in(t))
if (bag.count(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.in(Tile::Joker()))
if (!jokerFound && bag.count(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.in(Tile::Joker()))
while (bag.count(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.in(replacingTile))
if (bag.count(replacingTile))
{
// The bag contains the replacing letter
// We need to swap the joker (it is necessarily in the
@ -525,7 +525,7 @@ bool Game::rackInBag(const Rack &iRack, const Bag &iBag) const
{
BOOST_FOREACH(const Tile &t, getDic().getAllTiles())
{
if (iRack.in(t) > iBag.in(t))
if (iRack.in(t) > iBag.count(t))
return false;
}
return true;

View file

@ -88,7 +88,7 @@ void BagWidget::updateModel()
const Bag &bag = m_game->getBag();
BOOST_FOREACH(const Tile &tile, m_game->getDic().getAllTiles())
{
unsigned int nb = bag.in(tile);
unsigned int nb = bag.count(tile);
if (nb != 0)
{
// Concatenate the display char nb times
@ -105,7 +105,7 @@ void BagWidget::updateModel()
labelVowels->setText(QString("%1").arg(bag.getNbVowels()));
labelConsonants->setText(QString("%1").arg(bag.getNbConsonants()));
labelJokers->setText(QString("%1").arg(bag.in(Tile::Joker())));
labelJokers->setText(QString("%1").arg(bag.count(Tile::Joker())));
}
@ -200,7 +200,7 @@ void BagWidget2::refresh()
unsigned int index = 0;
BOOST_FOREACH(const Tile &tile, m_game->getDic().getAllTiles())
{
const unsigned int nbInBag = bag.in(tile);
const unsigned int nbInBag = bag.count(tile);
const unsigned int nbInRack = rack.in(tile);
ASSERT(nbInBag >= nbInRack, "Unexpected letters in the rack");
for (unsigned i = 0; i < nbInBag - nbInRack; ++i)

View file

@ -267,7 +267,7 @@ void MainWindow::refresh()
m_lettersLabel->setText(_q("Consonants: %1 | Vowels: %2 | Jokers: %3")
.arg(bag.getNbConsonants())
.arg(bag.getNbVowels())
.arg(bag.in(Tile::Joker())));
.arg(bag.count(Tile::Joker())));
unsigned currTurn = m_game->getCurrTurn();
m_turnLabel->setText(_q("Turn %1/%2")
.arg(currTurn)

View file

@ -158,7 +158,7 @@ QValidator::State RackValidator::validate(QString &input, int &) const
for (int i = 0; i < qinput.size(); ++i)
{
if ((unsigned int)qinput.count(qinput[i], Qt::CaseInsensitive) >
m_bag.in(intInput[i]))
m_bag.count(intInput[i]))
{
// ... except if they are part of a multichar input string
if (dic.getHeader().isMultiCharPart(intInput[i]))

View file

@ -143,7 +143,7 @@ void GameIO::printNonPlayed(ostream &out, const PublicGame &iGame)
const Bag &bag = iGame.getBag();
BOOST_FOREACH(const Tile &tile, iGame.getDic().getAllTiles())
{
if (bag.in(tile) > 9)
if (bag.count(tile) > 9)
out << " ";
out << setw(2) << lfw(tile.getDisplayStr());
}
@ -151,7 +151,7 @@ void GameIO::printNonPlayed(ostream &out, const PublicGame &iGame)
BOOST_FOREACH(const Tile &tile, iGame.getDic().getAllTiles())
{
out << " " << bag.in(tile);
out << " " << bag.count(tile);
}
out << endl;
}

View file

@ -516,7 +516,7 @@ void CursesIntf::drawBag(Box &ioBox) const
{
const wstring &chr = allTiles[i].getDisplayStr();
wstring str;
for (unsigned int j = 0; j < m_game->getBag().in(allTiles[i]); ++j)
for (unsigned int j = 0; j < m_game->getBag().count(allTiles[i]); ++j)
str += chr;
ioBox.printDataLine(i, ioBox.getLeft() + 1,
" %s %2d %2d %s",