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 #ifndef _BAG_H_ 00022 #define _BAG_H_ 00023 00024 #include "tile.h" 00025 #include <map> 00026 00027 using std::map; 00028 00029 00030 /** 00031 * A bag stores the set of free tiles for the game. 00032 */ 00033 class Bag 00034 { 00035 public: 00036 Bag(); 00037 virtual ~Bag() {} 00038 void init(); 00039 00040 /// Take a tile in the bag 00041 void takeTile(const Tile &iTile); 00042 /// Replace a tile into the bag 00043 void replaceTile(const Tile &iTile); 00044 00045 /// Return how many tiles identical to iTile are available in the bag 00046 unsigned int in(const Tile &iTile) const; 00047 00048 /** 00049 * Return how many tiles/vowels/consonants are available 00050 * Warning: nVowels(b) + nConsonants(b) != nTiles(b), 00051 * because of the jokers and the 'Y'. 00052 */ 00053 unsigned int nTiles() const { return m_ntiles; } 00054 unsigned int nVowels() const; 00055 unsigned int nConsonants() const; 00056 00057 /** 00058 * Return a random available tile 00059 * The tile is not taken out of the bag. 00060 */ 00061 Tile selectRandom(); 00062 00063 void operator=(const Bag &iOther); 00064 00065 /// Print on stderr all the letters of the bag (for debugging purposes) 00066 void dumpAll() const; 00067 00068 private: 00069 /// Associate to each tile its number of occurrences in the bag 00070 map<Tile, int> m_tilesMap; 00071 /// Total number of tiles in the bag 00072 int m_ntiles; 00073 }; 00074 00075 #endif 00076 00077 /// Local Variables: 00078 /// mode: c++ 00079 /// mode: hs-minor 00080 /// c-basic-offset: 4 00081 /// indent-tabs-mode: nil 00082 /// End: