eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/game cross.cpp cross.h tile.cpp tile.h [multibyte]


From: eliot-dev
Subject: [Eliot-dev] eliot/game cross.cpp cross.h tile.cpp tile.h [multibyte]
Date: Sun, 08 Jan 2006 11:52:36 +0000

CVSROOT:        /sources/eliot
Module name:    eliot
Branch:         multibyte
Changes by:     Olivier Teulière <address@hidden>      06/01/08 11:52:36

Modified files:
        game           : cross.cpp cross.h tile.cpp tile.h 

Log message:
        Use a mask instead of a set of tiles for cross checks.
        The speed benefit is not that big though.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/cross.cpp.diff?only_with_tag=multibyte&tr1=1.4.2.1&tr2=1.4.2.2&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/cross.h.diff?only_with_tag=multibyte&tr1=1.5.2.1&tr2=1.5.2.2&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/tile.cpp.diff?only_with_tag=multibyte&tr1=1.5.2.2&tr2=1.5.2.3&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/tile.h.diff?only_with_tag=multibyte&tr1=1.6.2.2&tr2=1.6.2.3&r1=text&r2=text

Patches:
Index: eliot/game/cross.cpp
diff -u eliot/game/cross.cpp:1.4.2.1 eliot/game/cross.cpp:1.4.2.2
--- eliot/game/cross.cpp:1.4.2.1        Tue Jan  3 20:42:13 2006
+++ eliot/game/cross.cpp        Sun Jan  8 11:52:36 2006
@@ -22,45 +22,33 @@
 
 Cross::Cross()
 {
-    // the default behaviour is to match everything
+    // The default behaviour is to match everything
     m_any = true;
+    m_mask = 0xFFFFFFFF;
 }
 
 
 void Cross::clear()
 {
-    m_tilesSet.clear();
     m_any = false;
+    m_mask = 0;
 }
 
 
 bool Cross::check(const Tile& iTile) const
 {
-    if (m_any || (iTile.isJoker() && !m_tilesSet.empty()))
+    if (m_any || (iTile.isJoker() && m_mask != 0))
         return true;
-    set<Tile>::const_iterator it = m_tilesSet.find(iTile);
-    return it != m_tilesSet.end();
+    return m_mask & (1 << iTile.toCode());
 }
 
 
 bool Cross::operator==(const Cross &iOther) const
 {
-    if (isAny() && iOther.isAny())
-        return true;
-    // Two sets are equal if they have the same size and one of them contains
-    // the other one
-    if (m_tilesSet.size() == iOther.m_tilesSet.size())
-    {
-        set<Tile>::const_iterator it;
-        for (it = m_tilesSet.begin(); it != m_tilesSet.end(); it++)
-        {
-            if (!iOther.check(*it))
-                return false;
-        }
-        return true;
-    }
-    else
-        return false;
+    if (isAny() || iOther.isAny())
+        return isAny() && iOther.isAny();
+
+    return m_mask == iOther.m_mask;
 }
 
 /// Local Variables:
Index: eliot/game/cross.h
diff -u eliot/game/cross.h:1.5.2.1 eliot/game/cross.h:1.5.2.2
--- eliot/game/cross.h:1.5.2.1  Tue Jan  3 20:42:13 2006
+++ eliot/game/cross.h  Sun Jan  8 11:52:36 2006
@@ -20,8 +20,8 @@
 #ifndef _CROSS_H_
 #define _CROSS_H_
 
-#include "tile.h"
 #include <set>
+#include "tile.h"
 
 using namespace std;
 
@@ -44,15 +44,14 @@
     bool operator!=(const Cross &iOther) const { return !(*this == iOther); }
 
     // Standard set methods (almost)
-    unsigned int size() const       { return m_tilesSet.size(); }
-    void insert(const Tile& iTile)  { m_tilesSet.insert(iTile); }
+    void insert(const Tile& iTile)  { m_mask |= (1 << iTile.toCode()); }
     void clear();
 
 private:
-    // Set of the tiles accepted for the cross check
-    set<Tile> m_tilesSet;
+    /// Mask indicating which tiles are accepted for the cross check
+    unsigned int m_mask;
 
-    // When this value is true, any letter matches the cross check
+    /// When this value is true, any letter matches the cross check
     bool m_any;
 };
 
Index: eliot/game/tile.cpp
diff -u eliot/game/tile.cpp:1.5.2.2 eliot/game/tile.cpp:1.5.2.3
--- eliot/game/tile.cpp:1.5.2.2 Tue Jan  3 20:42:13 2006
+++ eliot/game/tile.cpp Sun Jan  8 11:52:36 2006
@@ -79,18 +79,21 @@
         m_joker = true;
         m_dummy = false;
         m_char = TILE_JOKER;
+        m_code = 27;
     }
     else if (isalpha(c))
     {
         m_joker = islower(c);
         m_dummy = false;
         m_char = toupper(c);
+        m_code = m_char - 'A' + 1;
     }
     else
     {
         m_joker = false;
         m_dummy = true;
         m_char = 0;
+        m_code = 0;
     }
 }
 
@@ -164,11 +167,7 @@
 
 int Tile::toCode() const
 {
-    if (m_dummy)
-        return TILE_IDX_DUMMY;
-    if (m_joker)
-        return TILE_IDX_DUMMY;
-    return (TILE_IDX_START + m_char - TILE_START);
+    return m_code;
 }
 
 bool Tile::operator <(const Tile &iOther) const
Index: eliot/game/tile.h
diff -u eliot/game/tile.h:1.6.2.2 eliot/game/tile.h:1.6.2.3
--- eliot/game/tile.h:1.6.2.2   Tue Jan  3 20:42:13 2006
+++ eliot/game/tile.h   Sun Jan  8 11:52:36 2006
@@ -64,6 +64,12 @@
     bool m_joker;
     bool m_dummy;
 
+    /**
+     * Internal code, used in the dictionary to represent the letter.
+     * It is mainly used by the Cross class.
+     */
+    int m_code;
+
     // Special tiles are declared static
     static const Tile m_TheJoker;
     static const Tile m_TheDummy;




reply via email to

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