From 3f4c290745749f103f6e6e51645cc9c293f26bde Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Mon, 26 Dec 2005 22:53:26 +0000 Subject: [PATCH] - modified to use History - add setRack wrapper for both manual and random --- game/training.cpp | 83 ++++++++++++++++++++++++++++++----------------- game/training.h | 4 ++- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/game/training.cpp b/game/training.cpp index 4ba9525..19bad12 100644 --- a/game/training.cpp +++ b/game/training.cpp @@ -38,32 +38,6 @@ Training::~Training() { } - -int Training::play(const string &iCoord, const string &iWord) -{ - /* Perform all the validity checks, and fill a round */ - Round round; - int res = checkPlayedWord(iCoord, iWord, round); - if (res != 0) - { - return res; - } - - /* Update the rack and the score of the current player */ - m_players[m_currPlayer]->addPoints(round.getPoints()); - m_players[m_currPlayer]->endTurn(round, getNTurns()); - - /* Everything is OK, we can play the word */ - helperPlayRound(round); - - /* Next turn */ - // XXX: Should it be done by the interface instead? - endTurn(); - - return 0; -} - - int Training::setRackRandom(int p, bool iCheck, set_rack_mode mode) { int res; @@ -78,7 +52,6 @@ int Training::setRackRandom(int p, bool iCheck, set_rack_mode mode) return res; } - int Training::setRackManual(bool iCheck, const string &iLetters) { int res; @@ -101,6 +74,48 @@ int Training::setRackManual(bool iCheck, const string &iLetters) return res; } +int Training::setRack(set_rack_mode iMode, bool iCheck, const string &iLetters) +{ + int res = 0; + switch(iMode) + { + case RACK_MANUAL: + res = setRackManual(iCheck, iLetters); + break; + case RACK_ALL: + res = setRackRandom(m_currPlayer, iCheck, iMode); + break; + case RACK_NEW: + res = setRackRandom(m_currPlayer, iCheck, iMode); + break; + } + return res; +} + +int Training::play(const string &iCoord, const string &iWord) +{ + /* Perform all the validity checks, and fill a round */ + Round round; + int res = checkPlayedWord(iCoord, iWord, round); + if (res != 0) + { + return res; + } + + /* Update the rack and the score of the current player */ + m_players[m_currPlayer]->addPoints(round.getPoints()); + m_players[m_currPlayer]->endTurn(round, m_history.getSize()); + + /* Everything is OK, we can play the word */ + helperPlayRound(round); + + /* Next turn */ + // XXX: Should it be done by the interface instead? + endTurn(); + + return 0; +} + int Training::start() { @@ -113,7 +128,6 @@ int Training::start() return 0; } - int Training::endTurn() { // Nothing to do? @@ -126,7 +140,8 @@ void Training::search() // Search for the current player Rack r; m_players[m_currPlayer]->getCurrentRack().getRack(r); - m_results.search(*m_dic, m_board, r, getNTurns()); + debug("Training::search for %s\n",r.toString().c_str()); + m_results.search(*m_dic, m_board, r, m_history.getSize()); } @@ -139,7 +154,7 @@ int Training::playResult(int n) /* Update the rack and the score of the current player */ player->addPoints(round.getPoints()); - player->endTurn(round, getNTurns()); + player->endTurn(round, m_history.getSize()); int res = helperPlayRound(round); @@ -187,3 +202,11 @@ std::string Training::getTestPlayWord() const return m_testRound.getWord(); } +/****************************************************************/ +/****************************************************************/ + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// End: diff --git a/game/training.h b/game/training.h index 9d770ee..28efe0d 100644 --- a/game/training.h +++ b/game/training.h @@ -47,12 +47,14 @@ public: * Game handling *************************/ virtual int start(); - virtual int setRackRandom(int, bool, set_rack_mode); virtual int play(const string &iCoord, const string &iWord); virtual int endTurn(); void search(); int playResult(int); + + virtual int setRackRandom(int, bool, set_rack_mode); int setRackManual(bool iCheck, const string &iLetters); + int setRack(set_rack_mode iMode, bool iCheck, const string &iLetters); /************************* * Override the default behaviour of these methods, because in training