- 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)
This commit is contained in:
Antoine Fraboulet 2006-01-01 19:47:26 +00:00
parent 63005cdddb
commit 5bdca9e9fd
2 changed files with 104 additions and 13 deletions

View file

@ -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<Tile>::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<Tile>::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:

View file

@ -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<Tile> &oTiles) const;
void getAllTiles(vector<Tile> &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<Tile> m_oldTiles;
vector<Tile> m_newTiles;
};
#endif
/// Local Variables:
/// mode: c++
/// mode: hs-minor
/// c-basic-offset: 4
/// indent-tabs-mode: nil
/// End: