[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Eliot-dev] Changes to eliot/game/pldrack.cpp [antoine-1]
From: |
eliot-dev |
Subject: |
[Eliot-dev] Changes to eliot/game/pldrack.cpp [antoine-1] |
Date: |
Sun, 23 Oct 2005 13:16:35 -0400 |
Index: eliot/game/pldrack.cpp
diff -u /dev/null eliot/game/pldrack.cpp:1.5.2.1
--- /dev/null Sun Oct 23 17:16:35 2005
+++ eliot/game/pldrack.cpp Sun Oct 23 17:16:24 2005
@@ -0,0 +1,286 @@
+/*****************************************************************************
+ * Copyright (C) 1999-2005 Eliot
+ * Authors: Antoine Fraboulet <address@hidden>
+ * Olivier Teuliere <address@hidden>
+ *
+<<<<<<< pldrack.cpp
+=======
+ * $Id: pldrack.cpp,v 1.5.2.1 2005/10/23 17:16:24 afrab Exp $
+ *
+>>>>>>> 1.5
+ * 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
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *****************************************************************************/
+
+/* $Id: pldrack.cpp,v 1.5.2.1 2005/10/23 17:16:24 afrab Exp $ */
+
+/**
+ * \file pldrack.cpp
+ * \brief Improved Rack class with old and new tiles
+ * \author Antoine Fraboulet & Olivier Teuliere
+ * \date 2002 - 2005
+ */
+
+#include <string>
+#include "rack.h"
+#include "pldrack.h"
+
+#include "debug.h"
+
+const int PlayedRack::RACK_SIZE = 7;
+
+PlayedRack::PlayedRack()
+{
+ reset();
+ reject = false;
+}
+
+int PlayedRack::replace(Bag& bag, set_rack_mode mode, const std::string
manual_rack)
+{
+ int res = 0;
+ int tiles_to_take = 0;
+ std::vector<Tile> tiles;
+
+ // 1: we replace the tiles from the old rack in the bag
+ // kept tiles are kept and placed in the current rack
+ switch (mode)
+ {
+ case RACK_NEW:
+ bag.putbackTiles(m_newTiles);
+ resetNew();
+ tiles_to_take = RACK_SIZE - m_oldTiles.size();
+ break;
+ case RACK_ALL:
+ if (m_oldTiles.size() > 0)
+ reject = true;
+ /* fall */
+ case RACK_MANUAL:
+ /// TODO: set reject boolean for RACK_MANUAL
+ bag.putbackTiles(m_oldTiles);
+ bag.putbackTiles(m_newTiles);
+ reset();
+ tiles_to_take = RACK_SIZE;
+ break;
+ }
+
+ // 2: we take some random tiles or the proposed tiles
+ tiles.clear();
+ if (mode == RACK_MANUAL)
+ {
+ std::string::iterator it;
+ std::string uLetters = manual_rack;
+ for(it = uLetters.begin(); it != uLetters.end(); it ++)
+ {
+ *it = toupper(*it);
+ Tile t = Tile(*it);
+ if (bag.in(t) < 1)
+ {
+ res = 1;
+ break;
+ }
+ bag.takeTile(t);
+ tiles.push_back(t);
+ }
+ }
+ else
+ {
+ res = bag.takeRandomTiles(tiles_to_take,tiles);
+ }
+
+ // 3: we set the rack
+ m_newTiles = tiles;
+ return res;
+}
+
+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(std::vector<Tile> &oTiles) const
+{
+ oTiles.clear();
+ for (int i = 0; i < nOld(); i++)
+ oTiles.push_back(m_oldTiles[i]);
+}
+
+
+void PlayedRack::getNewTiles(std::vector<Tile> &oTiles) const
+{
+ oTiles.clear();
+ for (int i = 0; i < nNew(); i++)
+ oTiles.push_back(m_newTiles[i]);
+}
+
+
+void PlayedRack::getAllTiles(std::vector<Tile> &oTiles) const
+{
+ oTiles.clear();
+ for (int i = 0; i < nOld(); i++)
+ oTiles.push_back(m_oldTiles[i]);
+ for (int j = 0; j < nNew(); j++)
+ oTiles.push_back(m_newTiles[j]);
+}
+
+
+void PlayedRack::reset()
+{
+ m_oldTiles.clear();
+ m_newTiles.clear();
+}
+
+
+void PlayedRack::resetNew()
+{
+ m_newTiles.clear();
+}
+
+
+void PlayedRack::getOld(Rack &oRack) const
+{
+ std::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
+{
+ std::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
+{
+ std::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)
+{
+ std::list<Tile> l;
+ iRack.getTiles(l);
+
+ m_oldTiles.clear();
+ std::list<Tile>::const_iterator it;
+ for (it = l.begin(); it != l.end(); it++)
+ {
+ addOld(*it);
+ }
+}
+
+
+void PlayedRack::setNew(const Rack &iRack)
+{
+ std::list<Tile> l;
+ iRack.getTiles(l);
+
+ m_newTiles.clear();
+ std::list<Tile>::const_iterator it;
+ for (it = l.begin(); it != l.end(); it++)
+ {
+ addNew(*it);
+ }
+}
+
+
+bool PlayedRack::checkRack(int cMin, int vMin) const
+{
+ std::vector<Tile>::const_iterator it;
+ int v = 0;
+ int c = 0;
+
+ 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++;
+ }
+ return (v >= vMin) && (c >= cMin);
+}
+
+
+void PlayedRack::operator=(const PlayedRack &iOther)
+{
+ m_oldTiles = iOther.m_oldTiles;
+ m_newTiles = iOther.m_newTiles;
+}
+
+
+std::string PlayedRack::toString(int size, display_mode mode) const
+{
+ std::string s("");
+ std::vector<Tile>::const_iterator it;
+
+ if (nOld() > 0)
+ {
+ for (it = m_oldTiles.begin(); it != m_oldTiles.end(); it++)
+ s += it->toChar();
+ }
+
+ if (mode > RACK_SIMPLE && nOld() > 0 && nNew() > 0)
+ {
+ s += "+";
+ }
+
+ if (mode > RACK_EXTRA && reject)
+ {
+ s += "-";
+ // nouveau tirage : rejet
+ // pas après un scrabble
+ }
+
+ if (nNew() > 0)
+ {
+ for (it = m_newTiles.begin(); it != m_newTiles.end(); it++)
+ s += it->toChar();
+ }
+
+ if (size > 0 && (unsigned int)size > s.size())
+ {
+ s += std::string(size - s.size(), ' ');
+ }
+
+ return s;
+}
+
+
+/// Local Variables:
+/// mode: hs-minor
+/// c-basic-offset: 4
+/// End:
- [Eliot-dev] Changes to eliot/game/pldrack.cpp [antoine-1],
eliot-dev <=