From 6e2c665bdf014d0baaa4cf955bbfb0538a2ca47b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 19 Feb 2012 10:31:05 +0100 Subject: [PATCH] Simplify the handling of jokers in the Round class. This also fixes a very old (but minor) bug: when a word containing a joker was played "manually" (i.e. not via a round generated by the Results class but via the Game::checkPlayedWord() method), subsequent search results using this joker on the board would display it as a joker, not as a normal tile. --- game/game.cpp | 5 ----- game/game_move_cmd.cpp | 6 ------ game/round.cpp | 44 +++++++++++++--------------------------- game/round.h | 3 +-- test/training_rosace.ref | 12 +++++------ test/training_search.ref | 38 +++++++++++++++++----------------- 6 files changed, 40 insertions(+), 68 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index aa2167a..ac846a8 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -536,11 +536,6 @@ int Game::checkPlayedWord(const wstring &iCoord, tiles.push_back(Tile(iWord[i])); } oRound.setWord(tiles); - for (unsigned int i = 0; i < iWord.size(); i++) - { - if (islower(iWord[i])) - oRound.setJoker(i); - } // Check the word position, compute its points, // and specify the origin of each letter (board or rack) diff --git a/game/game_move_cmd.cpp b/game/game_move_cmd.cpp index de46172..ea54cde 100644 --- a/game/game_move_cmd.cpp +++ b/game/game_move_cmd.cpp @@ -119,12 +119,6 @@ void GameMoveCmd::playRound() bag.replaceTile(Tile::Joker()); bag.takeTile(t); m_round.setTile(i, t); - // FIXME: This shouldn't be necessary, this is only - // needed because of the stupid way of handling jokers in - // rounds - // This is also needed for the unplayRound() method - // to work correctly - m_round.setJoker(i, false); } // In a joker game we should have only 1 joker in the rack diff --git a/game/round.cpp b/game/round.cpp index 4e95d02..3d1e437 100644 --- a/game/round.cpp +++ b/game/round.cpp @@ -31,11 +31,6 @@ INIT_LOGGER(game, Round); -#define FROMBOARD 0x1 -#define FROMRACK 0x2 -#define JOKER 0x4 - - Round::Round() : m_coord(1, 1, Coord::HORIZONTAL), m_points(0), m_bonus(false) { @@ -46,36 +41,25 @@ void Round::setWord(const vector &iTiles) { m_word = iTiles; // XXX: always from rack? - m_tileOrigin = vector(iTiles.size(), FROMRACK); + m_rackOrigin = vector(iTiles.size(), true); } void Round::setFromRack(unsigned int iIndex) { - m_tileOrigin[iIndex] &= ~FROMBOARD; - m_tileOrigin[iIndex] |= FROMRACK; + m_rackOrigin[iIndex] = true; } void Round::setFromBoard(unsigned int iIndex) { - m_tileOrigin[iIndex] &= ~FROMRACK; - m_tileOrigin[iIndex] |= FROMBOARD; -} - - -void Round::setJoker(unsigned int iIndex, bool value) -{ - if (value) - m_tileOrigin[iIndex] |= JOKER; - else - m_tileOrigin[iIndex] &= ~JOKER; + m_rackOrigin[iIndex] = false; } bool Round::isJoker(unsigned int iIndex) const { - return m_tileOrigin[iIndex] & JOKER; + return m_word[iIndex].isJoker(); } @@ -87,33 +71,33 @@ const Tile& Round::getTile(unsigned int iIndex) const bool Round::isPlayedFromRack(unsigned int iIndex) const { - return m_tileOrigin[iIndex] & FROMRACK; + return m_rackOrigin[iIndex]; } void Round::addRightFromBoard(const Tile &iTile) { - m_word.push_back(iTile); - m_tileOrigin.push_back(FROMBOARD); + // The call to toUpper() is necessary to avoid that a joker + // on the board appears as a joker in the Round + m_word.push_back(iTile.toUpper()); + m_rackOrigin.push_back(false); } void Round::addRightFromRack(const Tile &iTile, bool iJoker) { - m_word.push_back(iTile); - char origin = FROMRACK; if (iJoker) - { - origin |= JOKER; - } - m_tileOrigin.push_back(origin); + m_word.push_back(iTile.toLower()); + else + m_word.push_back(iTile); + m_rackOrigin.push_back(true); } void Round::removeRight() { m_word.pop_back(); - m_tileOrigin.pop_back(); + m_rackOrigin.pop_back(); } diff --git a/game/round.h b/game/round.h index b1d6514..b4735f4 100644 --- a/game/round.h +++ b/game/round.h @@ -59,7 +59,6 @@ public: void setWord(const vector &iTiles); void setFromRack(unsigned int iIndex); void setFromBoard(unsigned int iIndex); - void setJoker(unsigned int iIndex, bool value = true); /************************* * General getters @@ -85,7 +84,7 @@ public: private: vector m_word; - vector m_tileOrigin; + vector m_rackOrigin; Coord m_coord; int m_points; bool m_bonus; diff --git a/test/training_rosace.ref b/test/training_rosace.ref index 2839551..8b94d3c 100644 --- a/test/training_rosace.ref +++ b/test/training_rosace.ref @@ -130,13 +130,13 @@ commande> a gd # r2 commande> r commande> a r 1: SaUGRENU * 82 E4 - 2: eNjUGUES * 66 D8 + 2: ENjUGUES * 66 D8 3: GUEUSANt * 66 11C - 4: NUaGEUSe * 66 D1 - 5: ENjUGUeS * 64 D2 - 6: GUEUSeNt * 64 D3 - 7: GUeUSENt * 64 D6 - 8: NUaGeUSE * 64 D4 + 4: NUaGEUSE * 66 D1 + 5: ENjUGUES * 64 D2 + 6: GUEUSENt * 64 D3 + 7: GUEUSENt * 64 D6 + 8: NUaGEUSE * 64 D4 9: GUeUSENT * 62 F1 10: GUEUSaNT * 60 F1 commande> a gd # r3 diff --git a/test/training_search.ref b/test/training_search.ref index 7d655d2..12979a8 100644 --- a/test/training_search.ref +++ b/test/training_search.ref @@ -863,39 +863,39 @@ commande> a r 50 15: Es 5 G7 16: Ex 5 G7 17: aIE 2 8G - 18: buE 2 7G - 19: duE 2 7G + 18: bUE 2 7G + 19: dUE 2 7G 20: EpI 2 8F - 21: Eu 2 7G - 22: Eue 2 7G - 23: euE 2 7G - 24: Euh 2 7G - 25: Eus 2 7G - 26: Eut 2 7G - 27: Eux 2 7G - 28: fEu 2 7F + 21: EU 2 7G + 22: EUe 2 7G + 23: eUE 2 7G + 24: EUh 2 7G + 25: EUs 2 7G + 26: EUt 2 7G + 27: EUx 2 7G + 28: fEU 2 7F 29: fIE 2 8G - 30: guE 2 7G - 31: hEu 2 7F + 30: gUE 2 7G + 31: hEU 2 7F 32: hIE 2 8G - 33: huE 2 7G + 33: hUE 2 7G 34: IdE 2 8H 35: IlE 2 8H 36: IpE 2 8H 37: IrE 2 8H 38: IvE 2 8H 39: IxE 2 8H - 40: jEu 2 7F + 40: jEU 2 7F 41: lEI 2 8F - 42: lEu 2 7F + 42: lEU 2 7F 43: lIE 2 8G - 44: luE 2 7G + 44: lUE 2 7G 45: mIE 2 8G - 46: muE 2 7G + 46: mUE 2 7G 47: nIE 2 8G - 48: nuE 2 7G + 48: nUE 2 7G 49: oIE 2 8G - 50: pEu 2 7F + 50: pEU 2 7F commande> q fin du mode entraƮnement commande> q