Results: add a isEmpty() method, and use it where possible

This commit is contained in:
Olivier Teulière 2013-01-16 11:09:28 +01:00
parent a881789676
commit 1e0de63ef8
9 changed files with 10 additions and 9 deletions

View file

@ -65,7 +65,7 @@ void AIPercent::compute(const Dictionary &iDic, const Board &iBoard, bool iFirst
Move AIPercent::getMove() const Move AIPercent::getMove() const
{ {
if (m_results->size() == 0) if (m_results->isEmpty())
{ {
// If there is no result, pass the turn. // If there is no result, pass the turn.
// FIXME: in duplicate mode, we should return a move of type NO_MOVE // FIXME: in duplicate mode, we should return a move of type NO_MOVE

View file

@ -280,7 +280,7 @@ void Duplicate::endTurn()
const Rack &rack = const Rack &rack =
m_players[REF_PLAYER_ID]->getLastRack().getRack(); m_players[REF_PLAYER_ID]->getLastRack().getRack();
results.search(getDic(), getBoard(), rack, getHistory().beforeFirstRound()); results.search(getDic(), getBoard(), rack, getHistory().beforeFirstRound());
if (results.size() == 0) if (results.isEmpty())
{ {
// This would be very bad luck that no move is possible... // This would be very bad luck that no move is possible...
// It's probably not even possible, but let's be safe. // It's probably not even possible, but let's be safe.

View file

@ -453,7 +453,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
BestResults res; BestResults res;
res.search(getDic(), getBoard(), rack, getHistory().beforeFirstRound()); res.search(getDic(), getBoard(), rack, getHistory().beforeFirstRound());
if (res.size()) if (!res.isEmpty())
{ {
PlayedRack pldCopy = pld; PlayedRack pldCopy = pld;

View file

@ -52,6 +52,7 @@ public:
virtual ~Results() {} virtual ~Results() {}
unsigned int size() const { return m_rounds.size(); } unsigned int size() const { return m_rounds.size(); }
const Round & get(unsigned int) const; const Round & get(unsigned int) const;
bool isEmpty() const { return m_rounds.empty(); }
/** /**
* Perform a search on the board. Every time a word is found, * Perform a search on the board. Every time a word is found,

View file

@ -216,7 +216,7 @@ Move Topping::getTopMove() const
BestResults results; BestResults results;
results.search(getDic(), getBoard(), getHistory().getCurrentRack().getRack(), results.search(getDic(), getBoard(), getHistory().getCurrentRack().getRack(),
getHistory().beforeFirstRound()); getHistory().beforeFirstRound());
ASSERT(results.size() != 0, "No top move found"); ASSERT(!results.isEmpty(), "No top move found");
return Move(results.get(0)); return Move(results.get(0));
} }

View file

@ -472,7 +472,7 @@ void ArbitAssignments::setMasterMove()
results.search(m_game->getDic(), m_game->getBoard(), results.search(m_game->getDic(), m_game->getBoard(),
m_game->getCurrentRack().getRack(), m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound()); m_game->getHistory().beforeFirstRound());
ASSERT(results.size() != 0, "No possible valid move"); ASSERT(!results.isEmpty(), "No possible valid move");
int bestScore = results.get(0).getPoints(); int bestScore = results.get(0).getPoints();
if (bestScore > move.getScore()) if (bestScore > move.getScore())
{ {
@ -530,7 +530,7 @@ void ArbitAssignments::setDefaultMasterMove()
m_game->getCurrentRack().getRack(), m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound()); m_game->getHistory().beforeFirstRound());
// XXX: End of game // XXX: End of game
if (results.size() == 0) if (results.isEmpty())
return; return;
unsigned currIndex = 0; unsigned currIndex = 0;

View file

@ -721,7 +721,7 @@ int ArbitrationWidget::getBestScore() const
results.search(m_game->getDic(), m_game->getBoard(), results.search(m_game->getDic(), m_game->getBoard(),
m_game->getCurrentRack().getRack(), m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound()); m_game->getHistory().beforeFirstRound());
ASSERT(results.size() != 0, "No possible valid move"); ASSERT(!results.isEmpty(), "No possible valid move");
return results.get(0).getPoints(); return results.get(0).getPoints();
} }

View file

@ -192,7 +192,7 @@ void TrainingWidget::updateModel()
const Results &results = m_game->trainingGetResults(); const Results &results = m_game->trainingGetResults();
// Find the highest score // Find the highest score
int bestScore = -1; int bestScore = -1;
if (results.size() != 0) if (!results.isEmpty())
bestScore = results.get(0).getPoints(); bestScore = results.get(0).getPoints();
for (unsigned int i = 0; i < results.size(); ++i) for (unsigned int i = 0; i < results.size(); ++i)
{ {

View file

@ -339,7 +339,7 @@ void CursesIntf::drawScoresRacks(WINDOW *win, int y, int x) const
// Display a message when the search is complete // Display a message when the search is complete
if (m_game->getMode() == PublicGame::kTRAINING && if (m_game->getMode() == PublicGame::kTRAINING &&
m_game->trainingGetResults().size()) !m_game->trainingGetResults().isEmpty())
{ {
mvwprintw(win, y + 2*yOff - 1, x + 2, _("Search complete")); mvwprintw(win, y + 2*yOff - 1, x + 2, _("Search complete"));
} }