From 5bdca9e9fdefda817f736b5feb8ffdbf4780f0e8 Mon Sep 17 00:00:00 2001 From: Antoine Fraboulet Date: Sun, 1 Jan 2006 19:47:26 +0000 Subject: [PATCH] - pldrack.h add comments and emacs mode add modes for toString - pldrack.cpp add modes for toString add bool "reject", should be used later to notify a reject during game add setRack(string) --- game/pldrack.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++------ game/pldrack.h | 28 +++++++++++++-- 2 files changed, 104 insertions(+), 13 deletions(-) diff --git a/game/pldrack.cpp b/game/pldrack.cpp index 758f1f0..bee6daa 100644 --- a/game/pldrack.cpp +++ b/game/pldrack.cpp @@ -18,12 +18,24 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ +/** + * \file pldrack.cpp + * \brief Improved Rack class with old and new tiles + * \author Antoine Fraboulet & Olivier Teuliere + * \date 2002 - 2005 + */ + #include "rack.h" #include "pldrack.h" #include "debug.h" +PlayedRack::PlayedRack() +{ + reject = false; +} + void PlayedRack::addOld(const Tile &t) { m_oldTiles.push_back(t); @@ -135,8 +147,43 @@ void PlayedRack::setNew(const Rack &iRack) } } +int PlayedRack::setManual(const string& iLetters) +{ + unsigned int i; + reset(); -bool PlayedRack::checkRack(int iMin) const + if (iLetters.size() == 0) + { + return 0; /* empty is ok */ + } + + for (i = 0; i < iLetters.size() && iLetters[i] != '+'; i++) + { + Tile tile(iLetters[i]); + if (tile.isEmpty()) + { + return 1; /* */ + } + addOld(tile); + } + + if (i < iLetters.size() && iLetters[i] == '+') + { + for (i++; i < iLetters.size(); i++) + { + Tile tile(iLetters[i]); + if (tile.isEmpty()) + { + return 1; /* */ + } + addNew(tile); + } + } + + return 0; +} + +bool PlayedRack::checkRack(int cMin, int vMin) const { vector::const_iterator it; int v = 0; @@ -152,7 +199,7 @@ bool PlayedRack::checkRack(int iMin) const if (it->isVowel()) v++; if (it->isConsonant()) c++; } - return (v >= iMin) && (c >= iMin); + return (v >= vMin) && (c >= cMin); } @@ -163,19 +210,41 @@ void PlayedRack::operator=(const PlayedRack &iOther) } -string PlayedRack::toString(bool iShowExtraSigns) const +string PlayedRack::toString(display_mode mode) const { + string s(""); vector::const_iterator it; - string s; + + if (nOld() > 0) + { + for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++) + s += it->toChar(); + } - for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++) - s += it->toChar(); + if (mode > RACK_SIMPLE && nOld() > 0 && nNew() > 0) + { + s += "+"; + } - if (iShowExtraSigns && nOld() > 0 && nNew() > 0) - s += "+"; + if (mode > RACK_EXTRA && reject) + { + s += "-"; + // nouveau tirage : rejet + // pas après un scrabble + } - for (it = m_newTiles.begin(); it != m_newTiles.end(); it++) - s += it->toChar(); + if (nNew() > 0) + { + for (it = m_newTiles.begin(); it != m_newTiles.end(); it++) + s += it->toChar(); + } return s; } + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: diff --git a/game/pldrack.h b/game/pldrack.h index f0c1489..c8ec15d 100644 --- a/game/pldrack.h +++ b/game/pldrack.h @@ -18,6 +18,13 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *****************************************************************************/ +/** + * \file pldrack.h + * \brief Improved Rack class with old and new tiles + * \author Antoine Fraboulet & Olivier Teuliere + * \date 2002 - 2005 + */ + #ifndef _PLAYEDRACK_H_ #define _PLAYEDRACK_H_ @@ -39,7 +46,7 @@ using namespace std; class PlayedRack { public: - PlayedRack() {} + PlayedRack(); virtual ~PlayedRack() {} void reset(); @@ -51,6 +58,7 @@ public: void setOld(const Rack &iRack); void setNew(const Rack &iRack); + int setManual(const string& iLetters); int nTiles() const { return nNew() + nOld(); } int nNew() const { return m_newTiles.size(); } @@ -62,14 +70,28 @@ public: void getOldTiles(vector &oTiles) const; void getAllTiles(vector &oTiles) const; - bool checkRack(int iMin) const; + bool checkRack(int cMin, int vMin) const; void operator=(const PlayedRack &iOther); - string toString(bool iShowExtraSigns = true) const; + + typedef enum { + RACK_SIMPLE, + RACK_EXTRA, + RACK_DEBUG + } display_mode; + string toString(display_mode iShowExtraSigns = RACK_EXTRA) const; private: + bool reject; vector m_oldTiles; vector m_newTiles; }; #endif + +/// Local Variables: +/// mode: c++ +/// mode: hs-minor +/// c-basic-offset: 4 +/// indent-tabs-mode: nil +/// End: