PublicGame: more direct access to the game current rack

This commit is contained in:
Olivier Teulière 2012-03-26 07:48:33 +02:00
parent 82b5694a59
commit d6a2fc6e4e
9 changed files with 23 additions and 30 deletions

View file

@ -29,6 +29,7 @@
#include "game_exception.h"
#include "xml_writer.h"
#include "player.h"
#include "pldrack.h"
PublicGame::PublicGame(Game &iGame)
@ -80,6 +81,12 @@ const Bag& PublicGame::getBag() const
}
const PlayedRack& PublicGame::getCurrentRack() const
{
return m_game.getHistory().getCurrentRack();
}
const History& PublicGame::getHistory() const
{
return m_game.getHistory();

View file

@ -35,6 +35,7 @@ class Round;
class Results;
class LimitResults;
class Move;
class PlayedRack;
using namespace std;
@ -91,6 +92,8 @@ public:
const Board& getBoard() const;
/// Get the bag
const Bag& getBag() const;
/// Get the rack
const PlayedRack & getCurrentRack() const;
/// Get the history of the game */
const History& getHistory() const;

View file

@ -346,12 +346,6 @@ void ArbitAssignments::showMasterPreview()
}
Rack ArbitAssignments::getRack() const
{
return m_game->getHistory().getCurrentRack().getRack();
}
void ArbitAssignments::assignMasterMove()
{
if (m_game->isFinished())
@ -377,7 +371,8 @@ void ArbitAssignments::assignMasterMove()
// Warn if the selected move is not a top move
BestResults results;
results.search(m_game->getDic(), m_game->getBoard(),
getRack(), m_game->getHistory().beforeFirstRound());
m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound());
ASSERT(results.size() != 0, "No possible valid move");
int bestScore = results.get(0).getPoints();
if (bestScore > move.getScore())
@ -427,7 +422,8 @@ void ArbitAssignments::assignDefaultMasterMove()
// Search the best moves
BestResults results;
results.search(m_game->getDic(), m_game->getBoard(),
getRack(), m_game->getHistory().beforeFirstRound());
m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound());
// XXX: End of game
if (results.size() == 0)
return;
@ -468,7 +464,8 @@ void ArbitAssignments::assignTopMove()
{
BestResults results;
results.search(m_game->getDic(), m_game->getBoard(),
getRack(), m_game->getHistory().beforeFirstRound());
m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound());
// TODO: what if there are several moves?
if (results.size() == 1)
helperAssignMove(Move(results.get(0)));

View file

@ -93,10 +93,6 @@ private:
/// Force synchronizing the model with the players
void updatePlayersModel();
/// Return the rack for the current turn
// FIXME: this feature should be provided by the core
Rack getRack() const;
/// Helper method to return the ID of the selected player(s)
QSet<unsigned int> getSelectedPlayers() const;

View file

@ -197,7 +197,7 @@ ArbitrationWidget::ArbitrationWidget(QWidget *parent,
void ArbitrationWidget::refresh()
{
const PlayedRack &pldRack = m_game->getHistory().getCurrentRack();
const PlayedRack &pldRack = m_game->getCurrentRack();
// Update the rack only if needed, to avoid losing cursor position
QString qrack = qfw(pldRack.toString(PlayedRack::RACK_SIMPLE));
if (qrack != lineEditRack->text()) {
@ -369,7 +369,7 @@ void ArbitrationWidget::rackEdited(const QString &iText)
if (!QtCommon::requestConfirmation(msg, question))
{
// Restore the rack (visually)
const PlayedRack &pldRack = m_game->getHistory().getCurrentRack();
const PlayedRack &pldRack = m_game->getCurrentRack();
QString qrack = qfw(pldRack.toString(PlayedRack::RACK_SIMPLE));
lineEditRack->setText(qrack);
@ -632,18 +632,13 @@ void ArbitrationWidget::showPreview(const QItemSelection &iSelected)
}
Rack ArbitrationWidget::getRack() const
{
return m_game->getHistory().getCurrentRack().getRack();
}
int ArbitrationWidget::getBestScore() const
{
// Note: we could cache the result of this method
BestResults results;
results.search(m_game->getDic(), m_game->getBoard(),
getRack(), m_game->getHistory().beforeFirstRound());
m_game->getCurrentRack().getRack(),
m_game->getHistory().beforeFirstRound());
ASSERT(results.size() != 0, "No possible valid move");
return results.get(0).getPoints();
}

View file

@ -116,10 +116,6 @@ private:
int addSingleMove(const Move &iMove, int moveType,
unsigned int index, int bestScore);
/// Return the rack for the current turn
// FIXME: this feature should be provided by the core
Rack getRack() const;
int getBestScore() const;
/// Helper method to return a structured move for the selected result

View file

@ -117,7 +117,7 @@ void BagWidget2::refresh()
m_tilesVect.push_back(tileWidget);
}
const Rack &rack = m_game->getHistory().getCurrentRack().getRack();
const Rack &rack = m_game->getCurrentRack().getRack();
TileWidget::State previewState =
m_showTilesInRack ? TileWidget::PREVIEW : TileWidget::NORMAL;

View file

@ -26,7 +26,6 @@
#include "qtcommon.h"
#include "public_game.h"
#include "history.h"
#include "pldrack.h"
#include "debug.h"
@ -67,7 +66,7 @@ void RackWidget::refresh()
// Get the rack
vector<Tile> tiles;
m_game->getHistory().getCurrentRack().getAllTiles(tiles);
m_game->getCurrentRack().getAllTiles(tiles);
// Make sure we have as many widgets as there are letters in the rack
while (m_tilesVect.size() > tiles.size())

View file

@ -215,7 +215,7 @@ void GameIO::printNonPlayed(ostream &out, const PublicGame &iGame)
void GameIO::printPlayedRack(ostream &out, const PublicGame &iGame, int __UNUSED__ n)
{
out << lfw(iGame.getHistory().getCurrentRack().toString(PlayedRack::RACK_SIMPLE)) << endl;
out << lfw(iGame.getCurrentRack().toString(PlayedRack::RACK_SIMPLE)) << endl;
}