mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-30 20:34:27 +01:00
- 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:
parent
63005cdddb
commit
5bdca9e9fd
2 changed files with 104 additions and 13 deletions
|
@ -18,12 +18,24 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* 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 "rack.h"
|
||||||
#include "pldrack.h"
|
#include "pldrack.h"
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
|
|
||||||
|
PlayedRack::PlayedRack()
|
||||||
|
{
|
||||||
|
reject = false;
|
||||||
|
}
|
||||||
|
|
||||||
void PlayedRack::addOld(const Tile &t)
|
void PlayedRack::addOld(const Tile &t)
|
||||||
{
|
{
|
||||||
m_oldTiles.push_back(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;
|
vector<Tile>::const_iterator it;
|
||||||
int v = 0;
|
int v = 0;
|
||||||
|
@ -152,7 +199,7 @@ bool PlayedRack::checkRack(int iMin) const
|
||||||
if (it->isVowel()) v++;
|
if (it->isVowel()) v++;
|
||||||
if (it->isConsonant()) c++;
|
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;
|
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++)
|
if (mode > RACK_SIMPLE && nOld() > 0 && nNew() > 0)
|
||||||
s += it->toChar();
|
{
|
||||||
|
s += "+";
|
||||||
|
}
|
||||||
|
|
||||||
if (iShowExtraSigns && nOld() > 0 && nNew() > 0)
|
if (mode > RACK_EXTRA && reject)
|
||||||
s += "+";
|
{
|
||||||
|
s += "-";
|
||||||
|
// nouveau tirage : rejet
|
||||||
|
// pas après un scrabble
|
||||||
|
}
|
||||||
|
|
||||||
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
if (nNew() > 0)
|
||||||
s += it->toChar();
|
{
|
||||||
|
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
||||||
|
s += it->toChar();
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Local Variables:
|
||||||
|
/// mode: c++
|
||||||
|
/// mode: hs-minor
|
||||||
|
/// c-basic-offset: 4
|
||||||
|
/// indent-tabs-mode: nil
|
||||||
|
/// End:
|
||||||
|
|
|
@ -18,6 +18,13 @@
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
* 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_
|
#ifndef _PLAYEDRACK_H_
|
||||||
#define _PLAYEDRACK_H_
|
#define _PLAYEDRACK_H_
|
||||||
|
|
||||||
|
@ -39,7 +46,7 @@ using namespace std;
|
||||||
class PlayedRack
|
class PlayedRack
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PlayedRack() {}
|
PlayedRack();
|
||||||
virtual ~PlayedRack() {}
|
virtual ~PlayedRack() {}
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
@ -51,6 +58,7 @@ public:
|
||||||
|
|
||||||
void setOld(const Rack &iRack);
|
void setOld(const Rack &iRack);
|
||||||
void setNew(const Rack &iRack);
|
void setNew(const Rack &iRack);
|
||||||
|
int setManual(const string& iLetters);
|
||||||
|
|
||||||
int nTiles() const { return nNew() + nOld(); }
|
int nTiles() const { return nNew() + nOld(); }
|
||||||
int nNew() const { return m_newTiles.size(); }
|
int nNew() const { return m_newTiles.size(); }
|
||||||
|
@ -62,14 +70,28 @@ public:
|
||||||
void getOldTiles(vector<Tile> &oTiles) const;
|
void getOldTiles(vector<Tile> &oTiles) const;
|
||||||
void getAllTiles(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);
|
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:
|
private:
|
||||||
|
bool reject;
|
||||||
vector<Tile> m_oldTiles;
|
vector<Tile> m_oldTiles;
|
||||||
vector<Tile> m_newTiles;
|
vector<Tile> m_newTiles;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/// Local Variables:
|
||||||
|
/// mode: c++
|
||||||
|
/// mode: hs-minor
|
||||||
|
/// c-basic-offset: 4
|
||||||
|
/// indent-tabs-mode: nil
|
||||||
|
/// End:
|
||||||
|
|
Loading…
Add table
Reference in a new issue