From 482b5d674f9bebbf9e06cc838e78b1364c6c777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 12 Jan 2012 17:43:57 +0100 Subject: [PATCH] Previewing a Round is now possible in all the game types. It was only possible in Training mode. This change will be useful for the future arbitration mdoe. --- game/game.cpp | 12 ++++++++++++ game/game.h | 9 +++++++++ game/public_game.cpp | 24 ++++++++++++------------ game/public_game.h | 20 ++++++-------------- game/training.cpp | 15 +-------------- game/training.h | 14 ++------------ qt/training_widget.cpp | 19 ++++++++++++------- 7 files changed, 54 insertions(+), 59 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 7492780..36bb009 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -436,6 +436,18 @@ PlayedRack Game::helperSetRackManual(bool iCheck, const wstring &iLetters) const return pld; } + +void Game::setTestRound(const Round &iRound) +{ + m_board.testRound(iRound); +} + + +void Game::removeTestRound() +{ + m_board.removeTestRound(); +} + /********************************************************* *********************************************************/ diff --git a/game/game.h b/game/game.h index 7f5b901..08298cd 100644 --- a/game/game.h +++ b/game/game.h @@ -194,6 +194,15 @@ public: Round &oRound, bool checkRack = true) const; + /** + * Preview the given round on the board. + * It is up to the caller to provide a Round + * which makes sense for the current game. + */ + void setTestRound(const Round &iRound); + /** Remove the round set with setTestRound */ + void removeTestRound(); + private: /// Game characteristics GameParams m_params; diff --git a/game/public_game.cpp b/game/public_game.cpp index 4a2a4f9..de7571f 100644 --- a/game/public_game.cpp +++ b/game/public_game.cpp @@ -150,6 +150,18 @@ void PublicGame::shuffleRack() m_game.shuffleRack(); } + +void PublicGame::setTestRound(const Round &iRound) +{ + m_game.setTestRound(iRound); +} + + +void PublicGame::removeTestRound() +{ + m_game.removeTestRound(); +} + /***************************/ static Training & getTrainingGame(Game &iGame) @@ -194,18 +206,6 @@ void PublicGame::trainingSetRackManual(bool iCheck, const wstring &iLetters) getTrainingGame(m_game).setRackManual(iCheck, iLetters); } - -void PublicGame::trainingTestPlay(unsigned int iResultIndex) -{ - getTrainingGame(m_game).testPlay(iResultIndex); -} - - -void PublicGame::trainingRemoveTestPlay() -{ - getTrainingGame(m_game).removeTestPlay(); -} - /***************************/ static Duplicate & getDuplicateGame(Game &iGame) diff --git a/game/public_game.h b/game/public_game.h index 8ed6633..ab0a637 100644 --- a/game/public_game.h +++ b/game/public_game.h @@ -31,6 +31,7 @@ class Board; class History; class Player; class Navigation; +class Round; class Results; using namespace std; @@ -155,18 +156,14 @@ public: */ int computePoints(const wstring &iWord, const wstring &iCoord) const; - /** - * Go back to turn iTurn. - * We must have: iTurn < getHistory().getSize() - * Possible return values: - * 0: everything went fine - * 1: iTurn is invalid - */ - //int back(unsigned int iTurn); - /// Shuffle the rack of the current player void shuffleRack(); + /// Place a temporary word on the board for preview purposes + void setTestRound(const Round &iRound); + /// Remove the temporary word + void removeTestRound(); + /*************** * Training games * These methods throw an exception if the current game is not in @@ -192,11 +189,6 @@ public: void trainingSetRackManual(bool iCheck, const wstring &iLetters); - /// Place a temporary word on the board for preview purposes - void trainingTestPlay(unsigned int iResultIndex); - /// Remove the temporary word - void trainingRemoveTestPlay(); - /*************** * Duplicate games * These methods throw an exception if the current game is not in diff --git a/game/training.cpp b/game/training.cpp index abe8094..9fc7429 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -90,7 +90,7 @@ int Training::play(const wstring &iCoord, const wstring &iWord) // Perform all the validity checks, and fill a round Round round; - removeTestPlay(); + m_board.removeTestRound(); int res = checkPlayedWord(iCoord, iWord, round); if (res != 0) @@ -188,16 +188,3 @@ void Training::addPlayer(Player *iPlayer) Game::addPlayer(iPlayer); } - -void Training::testPlay(unsigned int num) -{ - ASSERT(num < m_results.size(), "Wrong result number"); - m_board.testRound(m_results.get(num)); -} - - -void Training::removeTestPlay() -{ - m_board.removeTestRound(); -} - diff --git a/game/training.h b/game/training.h index 333993a..2584e03 100644 --- a/game/training.h +++ b/game/training.h @@ -77,22 +77,12 @@ public: */ void setRackManual(bool iCheck, const wstring &iLetters); - /************************* + /** * Override the default behaviour of addPlayer(), because in training * mode we only want a human player - *************************/ + */ virtual void addPlayer(Player *iPlayer); - /************************* - * Functions to access the current search results - * The int parameter should be 0 <= int < getNResults - *************************/ - - /// Place a temporary word on the board for preview purposes - void testPlay(unsigned int iResultIndex); - /// Remove the temporary word - void removeTestPlay(); - private: /// Private constructor and destructor to force using the GameFactory class Training(const GameParams &iParams); diff --git a/qt/training_widget.cpp b/qt/training_widget.cpp index 9e56a1c..5284f98 100644 --- a/qt/training_widget.cpp +++ b/qt/training_widget.cpp @@ -33,6 +33,7 @@ #include "game_exception.h" #include "player.h" #include "results.h" +#include "debug.h" using namespace std; @@ -240,13 +241,17 @@ void TrainingWidget::enablePlayButton(const QItemSelection &iSelected, void TrainingWidget::showPreview(const QItemSelection &iSelected, const QItemSelection &) { - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); if (!iSelected.indexes().empty()) { // Use the hidden column to get the result number const QModelIndex &index = m_model->index(iSelected.indexes().first().row(), HIDDEN_COLUMN); - m_game->trainingTestPlay(m_model->data(index).toUInt()); + unsigned int resNb = m_model->data(index).toUInt(); + + const Results &results = m_game->trainingGetResults(); + ASSERT(resNb < results.size(), "Wrong result number"); + m_game->setTestRound(results.get(resNb)); emit gameUpdated(); } } @@ -275,7 +280,7 @@ void TrainingWidget::lockSizesChanged(bool checked) void TrainingWidget::on_lineEditRack_textEdited(const QString &iText) { // FIXME: first parameter is hardcoded - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); if (!lineEditRack->hasAcceptableInput()) { lineEditRack->setPalette(redPalette); @@ -300,7 +305,7 @@ void TrainingWidget::on_lineEditRack_textEdited(const QString &iText) void TrainingWidget::on_pushButtonRack_clicked() { - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); try { // FIXME: first parameter is hardcoded @@ -316,7 +321,7 @@ void TrainingWidget::on_pushButtonRack_clicked() void TrainingWidget::on_pushButtonComplement_clicked() { - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); try { // FIXME: first parameter is hardcoded @@ -332,7 +337,7 @@ void TrainingWidget::on_pushButtonComplement_clicked() void TrainingWidget::on_pushButtonSearch_clicked() { - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); emit notifyInfo(_q("Searching with rack '%1'...").arg(lineEditRack->text())); m_game->trainingSearch(); emit notifyInfo(_q("Search done")); @@ -354,7 +359,7 @@ void TrainingWidget::on_treeViewResults_doubleClicked(const QModelIndex &iIndex) { if (!iIndex.isValid()) return; - m_game->trainingRemoveTestPlay(); + m_game->removeTestRound(); // Use the hidden column to get the result number const QModelIndex &index = m_model->index(iIndex.row(), HIDDEN_COLUMN); m_game->trainingPlayResult(m_model->data(index).toUInt());