mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-29 20:34:56 +01:00
PublicGame: more direct access to the game current rack
This commit is contained in:
parent
82b5694a59
commit
d6a2fc6e4e
9 changed files with 23 additions and 30 deletions
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)));
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue