diff --git a/game/board_search.cpp b/game/board_search.cpp index 23cc55e..49325ee 100644 --- a/game/board_search.cpp +++ b/game/board_search.cpp @@ -63,11 +63,10 @@ void BoardSearch::search(Rack &iRack, Results &oResults, Coord::Direction iDir) vector rackTiles; iRack.getTiles(rackTiles); vector::const_iterator it; - Round partialWord; for (int row = 1; row <= BOARD_DIM; row++) { - partialWord.init(); + Round partialWord; partialWord.accessCoord().setDir(iDir); partialWord.accessCoord().setRow(row); int lastanchor = 0; @@ -150,7 +149,7 @@ void BoardSearch::leftPart(Rack &iRack, Round &ioPartialWord, leftPart(iRack, ioPartialWord, oResults, succ, iRow, iAnchor, iLimit - 1); ioPartialWord.accessCoord().setCol(ioPartialWord.getCoord().getCol() + 1); - ioPartialWord.removeRightToRack(l, false); + ioPartialWord.removeRight(); iRack.add(l); } if (hasJokerInRack) @@ -161,7 +160,7 @@ void BoardSearch::leftPart(Rack &iRack, Round &ioPartialWord, leftPart(iRack, ioPartialWord, oResults, succ, iRow, iAnchor, iLimit - 1); ioPartialWord.accessCoord().setCol(ioPartialWord.getCoord().getCol() + 1); - ioPartialWord.removeRightToRack(l, true); + ioPartialWord.removeRight(); iRack.add(Tile::Joker()); } } @@ -198,7 +197,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord, ioPartialWord.addRightFromRack(l, false); extendRight(iRack, ioPartialWord, oResults, succ, iRow, iCol + 1, iAnchor); - ioPartialWord.removeRightToRack(l, false); + ioPartialWord.removeRight(); iRack.add(l); } if (hasJokerInRack) @@ -207,7 +206,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord, ioPartialWord.addRightFromRack(l, true); extendRight(iRack, ioPartialWord, oResults, succ, iRow, iCol + 1, iAnchor); - ioPartialWord.removeRightToRack(l, true); + ioPartialWord.removeRight(); iRack.add(Tile::Joker()); } } @@ -224,7 +223,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord, ioPartialWord.addRightFromBoard(l); extendRight(iRack, ioPartialWord, oResults, succ, iRow, iCol + 1, iAnchor); - ioPartialWord.removeRightToBoard(l); + ioPartialWord.removeRight(); // The letter will be present only once in the dictionary, // so we can stop looping break; diff --git a/game/game.cpp b/game/game.cpp index 0d16419..aa2167a 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -513,7 +513,7 @@ int Game::checkPlayedWord(const wstring &iCoord, return 1; // Init the round with the given coordinates - oRound.init(); + oRound = Round(); oRound.accessCoord().setFromString(iCoord); if (!oRound.getCoord().isValid()) { diff --git a/game/round.cpp b/game/round.cpp index c7baaed..4e95d02 100644 --- a/game/round.cpp +++ b/game/round.cpp @@ -35,24 +35,10 @@ INIT_LOGGER(game, Round); #define FROMRACK 0x2 #define JOKER 0x4 -#define __UNUSED__ __attribute__((unused)) - Round::Round() + : m_coord(1, 1, Coord::HORIZONTAL), m_points(0), m_bonus(false) { - init(); -} - - -void Round::init() -{ - m_word.clear(); - m_tileOrigin.clear(); - m_coord.setRow(1); - m_coord.setCol(1); - m_coord.setDir(Coord::HORIZONTAL); - m_points = 0; - m_bonus = false; } @@ -105,24 +91,16 @@ bool Round::isPlayedFromRack(unsigned int iIndex) const } -void Round::addRightFromBoard(Tile c) +void Round::addRightFromBoard(const Tile &iTile) { - m_word.push_back(c); + m_word.push_back(iTile); m_tileOrigin.push_back(FROMBOARD); } -void Round::removeRightToBoard(Tile __UNUSED__ c) +void Round::addRightFromRack(const Tile &iTile, bool iJoker) { - // c is unused. - m_word.pop_back(); - m_tileOrigin.pop_back(); -} - - -void Round::addRightFromRack(Tile c, bool iJoker) -{ - m_word.push_back(c); + m_word.push_back(iTile); char origin = FROMRACK; if (iJoker) { @@ -132,13 +110,13 @@ void Round::addRightFromRack(Tile c, bool iJoker) } -void Round::removeRightToRack(Tile __UNUSED__ c, bool __UNUSED__ iJoker) +void Round::removeRight() { - // c is unused. m_word.pop_back(); m_tileOrigin.pop_back(); } + wstring Round::getWord() const { wstring s; @@ -153,6 +131,7 @@ wstring Round::getWord() const return s; } + wstring Round::toString() const { wostringstream oss; diff --git a/game/round.h b/game/round.h index 1c91ed1..b1d6514 100644 --- a/game/round.h +++ b/game/round.h @@ -41,19 +41,14 @@ class Round DEFINE_LOGGER(); public: - /************************* - * - *************************/ Round(); - void init(); /************************* * *************************/ - void addRightFromBoard(Tile); - void removeRightToBoard(Tile); - void addRightFromRack(Tile, bool); - void removeRightToRack(Tile, bool); + void addRightFromBoard(const Tile &iTile); + void addRightFromRack(const Tile &iTile, bool iJoker); + void removeRight(); /************************* * General setters