- Allow dictionaries without jokers

- The listdic binary now accepts non-alphabetical characters.
   But playing with such a dictionary is still impossible.
This commit is contained in:
Olivier Teulière 2010-01-01 18:01:35 +00:00
parent c878573183
commit 9b52668612
4 changed files with 34 additions and 12 deletions

View file

@ -137,13 +137,14 @@ void Dictionary::initializeTiles()
// "Activate" the dictionary by giving the header to the Tile class
Tile::SetHeader(*m_header);
// XXX: temp
Tile::m_TheJoker = Tile(Tile::kTILE_JOKER);
m_tilesVect.reserve(m_header->getLetters().size() + 1);
// Create a tile for each letter in the dictionary header
for (unsigned int i = 0; i < m_header->getLetters().size(); ++i)
m_tilesVect.push_back(Tile(m_header->getLetters()[i]));
{
const wchar_t &chr = m_header->getLetters()[i];
unsigned int code = m_header->getCodeFromChar(chr);
m_tilesVect.push_back(Tile(code, chr == Tile::kTILE_JOKER));
}
}

View file

@ -112,6 +112,8 @@ public:
DictType getType() const { return m_type; }
wstring getLetters() const { return m_letters; }
wstring getInputChars() const { return m_inputChars; }
unsigned int getMinCode() const { return 1; }
unsigned int getMaxCode() const { return m_letters.size(); }
uint8_t getPoints(unsigned int iCode) const { return m_points[iCode - 1]; }
uint8_t getFrequency(unsigned int iCode) const { return m_frequency[iCode - 1]; }
bool isVowel(unsigned int iCode) const { return m_vowels[iCode - 1]; }

View file

@ -64,6 +64,14 @@ Tile::Tile(wchar_t c)
}
Tile::Tile(unsigned int iCode, bool isJoker)
{
m_joker = isJoker;
m_code = iCode;
m_char = m_header->getCharFromCode(iCode);
}
bool Tile::isVowel() const
{
if (m_code == 0)
@ -166,3 +174,14 @@ bool Tile::operator!=(const Tile &iOther) const
return !(*this == iOther);
}
void Tile::SetHeader(const Header &iHeader)
{
m_header = &iHeader;
// The joker tile depends on the dictionary,
// because its code may be different
// But since it might be valid to play without jokers,
// we first check if the dictionary contains a joker.
if (m_header->getLetters().find(kTILE_JOKER) != wstring::npos)
Tile::m_TheJoker = Tile(kTILE_JOKER);
}

View file

@ -31,24 +31,24 @@ using namespace std;
class Header;
/*************************
/**
* A Tile is the internal representation
* used within the game library to
* handle letters
*************************/
* used within the dictionary to handle letters
*/
class Tile
{
friend class Dictionary;
public:
// a lowercase character is always a joker
// A lowercase character is always a joker
// - this permits to detect joker in already played games
// - we need to pay attention when inserting characters taken
// from user input
Tile(wchar_t c = kTILE_DUMMY);
// Second constructor, used when the code of the tile is known
Tile(unsigned int iCode, bool isJoker);
bool isEmpty() const { return m_char == kTILE_DUMMY; }
bool isJoker() const { return m_joker; }
bool isPureJoker() const { return m_char == kTILE_JOKER; }
@ -87,7 +87,7 @@ private:
static const Header *m_header;
/// Update the dictionary header
static void SetHeader(const Header &iHeader) { m_header = &iHeader; }
static void SetHeader(const Header &iHeader);
};
#endif