pldrack.cpp

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 1999-2005 Eliot
00003  * Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
00004  *          Olivier Teuliere  <ipkiss@via.ecp.fr>
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  *****************************************************************************/
00020 
00021 /**
00022  *  \file   pldrack.cpp
00023  *  \brief  Improved Rack class with old and new tiles
00024  *  \author Antoine Fraboulet & Olivier Teuliere
00025  *  \date   2002 - 2005
00026  */
00027 
00028 #include "rack.h"
00029 #include "pldrack.h"
00030 
00031 #include "debug.h"
00032 
00033 
00034 PlayedRack::PlayedRack()
00035 {
00036   reject = false;
00037 }
00038 
00039 void PlayedRack::addOld(const Tile &t)
00040 {
00041     m_oldTiles.push_back(t);
00042 }
00043 
00044 
00045 void PlayedRack::addNew(const Tile &t)
00046 {
00047     m_newTiles.push_back(t);
00048 }
00049 
00050 
00051 void PlayedRack::getOldTiles(vector<Tile> &oTiles) const
00052 {
00053     oTiles.clear();
00054     for (int i = 0; i < nOld(); i++)
00055         oTiles.push_back(m_oldTiles[i]);
00056 }
00057 
00058 
00059 void PlayedRack::getNewTiles(vector<Tile> &oTiles) const
00060 {
00061     oTiles.clear();
00062     for (int i = 0; i < nNew(); i++)
00063         oTiles.push_back(m_newTiles[i]);
00064 }
00065 
00066 
00067 void PlayedRack::getAllTiles(vector<Tile> &oTiles) const
00068 {
00069     oTiles.clear();
00070     for (int i = 0; i < nOld(); i++)
00071         oTiles.push_back(m_oldTiles[i]);
00072     for (int j = 0; j < nNew(); j++)
00073         oTiles.push_back(m_newTiles[j]);
00074 }
00075 
00076 
00077 void PlayedRack::reset()
00078 {
00079     m_oldTiles.clear();
00080     m_newTiles.clear();
00081 }
00082 
00083 
00084 void PlayedRack::resetNew()
00085 {
00086     m_newTiles.clear();
00087 }
00088 
00089 
00090 void PlayedRack::getOld(Rack &oRack) const
00091 {
00092     vector<Tile>::const_iterator it;
00093     oRack.clear();
00094     for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
00095     {
00096         oRack.add(*it);
00097     }
00098 }
00099 
00100 
00101 void PlayedRack::getNew(Rack &oRack) const
00102 {
00103     vector<Tile>::const_iterator it;
00104     oRack.clear();
00105     for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
00106     {
00107         oRack.add(*it);
00108     }
00109 }
00110 
00111 
00112 void PlayedRack::getRack(Rack &oRack) const
00113 {
00114     vector<Tile>::const_iterator it;
00115     getOld(oRack);
00116     for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
00117     {
00118         oRack.add(*it);
00119     }
00120 }
00121 
00122 
00123 void PlayedRack::setOld(const Rack &iRack)
00124 {
00125     list<Tile> l;
00126     iRack.getTiles(l);
00127 
00128     m_oldTiles.clear();
00129     list<Tile>::const_iterator it;
00130     for (it = l.begin(); it != l.end(); it++)
00131     {
00132         addOld(*it);
00133     }
00134 }
00135 
00136 
00137 void PlayedRack::setNew(const Rack &iRack)
00138 {
00139     list<Tile> l;
00140     iRack.getTiles(l);
00141 
00142     m_newTiles.clear();
00143     list<Tile>::const_iterator it;
00144     for (it = l.begin(); it != l.end(); it++)
00145     {
00146         addNew(*it);
00147     }
00148 }
00149 
00150 
00151 bool PlayedRack::checkRack(int iMin) const
00152 {
00153     vector<Tile>::const_iterator it;
00154     int v = 0;
00155     int c = 0;
00156 
00157     for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
00158     {
00159         if (it->isVowel()) v++;
00160         if (it->isConsonant()) c++;
00161     }
00162     for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
00163     {
00164         if (it->isVowel()) v++;
00165         if (it->isConsonant()) c++;
00166     }
00167     return (v >= iMin) && (c >= iMin);
00168 }
00169 
00170 
00171 void PlayedRack::operator=(const PlayedRack &iOther)
00172 {
00173     m_oldTiles = iOther.m_oldTiles;
00174     m_newTiles = iOther.m_newTiles;
00175 }
00176 
00177 
00178 string PlayedRack::toString(display_mode mode) const
00179 {
00180     string s("");
00181     vector<Tile>::const_iterator it;
00182   
00183     if (nOld() > 0)
00184     {
00185         for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
00186             s += it->toChar();
00187     }
00188 
00189     if (mode > RACK_SIMPLE && nOld() > 0 && nNew() > 0)
00190     {
00191         s += "+";
00192     }
00193 
00194     if (mode > RACK_EXTRA  && reject)
00195     {
00196         s += "-";
00197         // nouveau tirage : rejet
00198         // pas après un scrabble
00199     }
00200 
00201     if (nNew() > 0)
00202     {
00203         for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
00204             s += it->toChar();
00205     }
00206 
00207     return s;
00208 }
00209 
00210 /// Local Variables:
00211 /// mode: c++
00212 /// mode: hs-minor
00213 /// c-basic-offset: 4
00214 /// indent-tabs-mode: nil
00215 /// End:

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5