eliot-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Eliot-dev] eliot/dic dic.cpp header.h tile.cpp tile.h


From: Olivier Teulière
Subject: [Eliot-dev] eliot/dic dic.cpp header.h tile.cpp tile.h
Date: Fri, 01 Jan 2010 18:01:35 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       10/01/01 18:01:35

Modified files:
        dic            : dic.cpp header.h tile.cpp tile.h 

Log message:
         - Allow dictionaries without jokers
         - The listdic binary now accepts non-alphabetical characters.
           But playing with such a dictionary is still impossible.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/dic.cpp?cvsroot=eliot&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/header.h?cvsroot=eliot&r1=1.12&r2=1.13
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/tile.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/dic/tile.h?cvsroot=eliot&r1=1.7&r2=1.8

Patches:
Index: dic.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/dic.cpp,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- dic.cpp     3 Jul 2009 21:40:14 -0000       1.7
+++ dic.cpp     1 Jan 2010 18:01:35 -0000       1.8
@@ -137,13 +137,14 @@
     // "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));
+    }
 }
 
 

Index: header.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/header.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -b -r1.12 -r1.13
--- header.h    29 Nov 2009 16:01:31 -0000      1.12
+++ header.h    1 Jan 2010 18:01:35 -0000       1.13
@@ -112,6 +112,8 @@
     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]; }

Index: tile.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/tile.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- tile.cpp    28 Jun 2009 11:48:17 -0000      1.5
+++ tile.cpp    1 Jan 2010 18:01:35 -0000       1.6
@@ -64,6 +64,14 @@
 }
 
 
+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 @@
     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);
+}

Index: tile.h
===================================================================
RCS file: /cvsroot/eliot/eliot/dic/tile.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- tile.h      29 Nov 2009 16:01:31 -0000      1.7
+++ tile.h      1 Jan 2010 18:01:35 -0000       1.8
@@ -31,24 +31,24 @@
 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 @@
     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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]