2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2002-2007 Antoine Fraboulet & Olivier Teulière
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
|
|
|
|
* Olivier Teulière <ipkiss @@ gmail.com>
|
2005-02-05 12:14:56 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
2006-01-01 20:47:26 +01:00
|
|
|
/**
|
|
|
|
* \file pldrack.cpp
|
|
|
|
* \brief Improved Rack class with old and new tiles
|
|
|
|
* \author Antoine Fraboulet & Olivier Teuliere
|
|
|
|
* \date 2002 - 2005
|
|
|
|
*/
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
#include <algorithm>
|
2005-02-05 12:14:56 +01:00
|
|
|
#include "pldrack.h"
|
2008-01-08 14:52:32 +01:00
|
|
|
#include "rack.h"
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
|
2006-01-01 20:47:26 +01:00
|
|
|
PlayedRack::PlayedRack()
|
2008-01-08 14:52:32 +01:00
|
|
|
: m_reject(false)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
void PlayedRack::addOld(const Tile &t)
|
|
|
|
{
|
|
|
|
m_oldTiles.push_back(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::addNew(const Tile &t)
|
|
|
|
{
|
|
|
|
m_newTiles.push_back(t);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getOldTiles(vector<Tile> &oTiles) const
|
|
|
|
{
|
|
|
|
oTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
oTiles = m_oldTiles;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getNewTiles(vector<Tile> &oTiles) const
|
|
|
|
{
|
|
|
|
oTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
oTiles = m_newTiles;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getAllTiles(vector<Tile> &oTiles) const
|
|
|
|
{
|
|
|
|
oTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
oTiles = m_oldTiles;
|
|
|
|
oTiles.insert(oTiles.end(), m_newTiles.begin(), m_newTiles.end());
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::reset()
|
|
|
|
{
|
|
|
|
m_oldTiles.clear();
|
|
|
|
m_newTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
m_reject = false;
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::resetNew()
|
|
|
|
{
|
|
|
|
m_newTiles.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getOld(Rack &oRack) const
|
|
|
|
{
|
|
|
|
vector<Tile>::const_iterator it;
|
|
|
|
oRack.clear();
|
|
|
|
for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
|
|
|
|
{
|
|
|
|
oRack.add(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getNew(Rack &oRack) const
|
|
|
|
{
|
|
|
|
vector<Tile>::const_iterator it;
|
|
|
|
oRack.clear();
|
|
|
|
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
|
|
|
{
|
|
|
|
oRack.add(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::getRack(Rack &oRack) const
|
|
|
|
{
|
|
|
|
vector<Tile>::const_iterator it;
|
|
|
|
getOld(oRack);
|
|
|
|
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
|
|
|
{
|
|
|
|
oRack.add(*it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::setOld(const Rack &iRack)
|
|
|
|
{
|
|
|
|
m_oldTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
iRack.getTiles(m_oldTiles);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void PlayedRack::setNew(const Rack &iRack)
|
|
|
|
{
|
|
|
|
m_newTiles.clear();
|
2008-01-08 14:52:32 +01:00
|
|
|
iRack.getTiles(m_newTiles);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
void PlayedRack::setManual(const wstring& iLetters)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
|
|
|
reset();
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
// An empty rack is OK
|
|
|
|
if (iLetters.empty())
|
|
|
|
return;
|
2006-01-01 20:47:26 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
unsigned int i;
|
2006-01-22 13:23:52 +01:00
|
|
|
for (i = 0; i < iLetters.size() && iLetters[i] != L'+'; i++)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
addOld(Tile(iLetters[i]));
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
if (i < iLetters.size() && iLetters[i] == L'+')
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
|
|
|
for (i++; i < iLetters.size(); i++)
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
addNew(Tile(iLetters[i]));
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
|
|
bool PlayedRack::checkRack(unsigned int cMin, unsigned int vMin) const
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
vector<Tile>::const_iterator it;
|
2008-01-08 14:52:32 +01:00
|
|
|
unsigned int v = 0;
|
|
|
|
unsigned int c = 0;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
|
|
|
|
{
|
|
|
|
if (it->isVowel()) v++;
|
|
|
|
if (it->isConsonant()) c++;
|
|
|
|
}
|
|
|
|
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
|
|
|
{
|
|
|
|
if (it->isVowel()) v++;
|
|
|
|
if (it->isConsonant()) c++;
|
|
|
|
}
|
2006-01-01 20:47:26 +01:00
|
|
|
return (v >= vMin) && (c >= cMin);
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
void PlayedRack::shuffleNew()
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
std::random_shuffle(m_newTiles.begin(), m_newTiles.end());
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
2005-03-29 08:54:08 +02:00
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
wstring PlayedRack::toString(display_mode mode) const
|
2005-03-29 08:54:08 +02:00
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
wstring s;
|
2005-04-02 20:05:21 +02:00
|
|
|
vector<Tile>::const_iterator it;
|
2006-01-22 13:23:52 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
if (mode >= RACK_EXTRA && m_reject)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
s += L"-";
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
2005-11-05 16:48:59 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
if (getNbOld() > 0)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
|
|
|
|
s += it->toChar();
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
2005-11-05 16:48:59 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
if (mode > RACK_SIMPLE && getNbOld() > 0 && getNbNew() > 0)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
s += L"+";
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
2005-11-05 16:48:59 +01:00
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
if (getNbNew() > 0)
|
2006-01-01 20:47:26 +01:00
|
|
|
{
|
2006-01-22 13:23:52 +01:00
|
|
|
for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
|
|
|
|
s += it->toChar();
|
2006-01-01 20:47:26 +01:00
|
|
|
}
|
2005-11-05 16:48:59 +01:00
|
|
|
|
|
|
|
return s;
|
2005-03-29 08:54:08 +02:00
|
|
|
}
|
2006-01-01 20:47:26 +01:00
|
|
|
|
|
|
|
/// Local Variables:
|
|
|
|
/// mode: c++
|
|
|
|
/// mode: hs-minor
|
|
|
|
/// c-basic-offset: 4
|
|
|
|
/// indent-tabs-mode: nil
|
|
|
|
/// End:
|