eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/game game.cpp game.h public_game.cpp publ...


From: Olivier Teulière
Subject: [Eliot-dev] eliot/game game.cpp game.h public_game.cpp publ...
Date: Wed, 14 Jan 2009 21:53:38 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>       09/01/14 21:53:38

Modified files:
        game           : game.cpp game.h public_game.cpp public_game.h 
                         results.h 

Log message:
         - The core is now able to handle "explosive games" ("parties 
détonantes"). No interface uses this ability yet.
         - Fixed a bug in Game::helperSetRackRandom()

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&r1=1.51&r2=1.52
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&r1=1.46&r2=1.47
http://cvs.savannah.gnu.org/viewcvs/eliot/game/public_game.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/public_game.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/results.h?cvsroot=eliot&r1=1.11&r2=1.12

Patches:
Index: game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -b -r1.51 -r1.52
--- game.cpp    11 Jan 2009 14:20:35 -0000      1.51
+++ game.cpp    14 Jan 2009 21:53:37 -0000      1.52
@@ -183,7 +183,7 @@
 
     bool jokerAdded = false;
     // Are we dealing with a normal game or a joker game?
-    if (m_variant == kJOKER)
+    if (m_variant == kJOKER || m_variant == kEXPLOSIVE)
     {
         // 1) Is there already a joker in the remaining letters of the rack?
         bool jokerFound = false;
@@ -205,7 +205,7 @@
         }
 
         // 3) Remove all the jokers from the bag, to avoid taking another one
-        for (unsigned int i = 0; i < bag.in(Tile::Joker()); ++i)
+        while (bag.in(Tile::Joker()))
         {
             bag.takeTile(Tile::Joker());
         }
@@ -323,6 +323,63 @@
         }
     }
 
+    // In explosive games, we have to perform a search, then replace the
+    // joker with the letter providing the best score
+    // A joker coming from a previous rack is not replaced
+    if (m_variant == kEXPLOSIVE && jokerAdded)
+    {
+        Rack rack;
+        pld.getRack(rack);
+
+        Results res;
+        res.search(getDic(), getBoard(), rack,  
getHistory().beforeFirstRound());
+        if (res.size())
+        {
+            PlayedRack pldCopy = pld;
+
+            // Get the best word
+            const Round & bestRound = res.get(0);
+#ifdef DEBUG
+                    cout << "helperSetRackRandom(): initial rack: "
+                         << convertToMb(pld.toString()) << " (best word: "
+                         << convertToMb(bestRound.getWord()) << ")" << endl;
+#endif
+            // Identify the joker
+            for (unsigned int i = 0; i < bestRound.getWordLen(); ++i)
+            {
+                if (bestRound.isJoker(i) && bestRound.isPlayedFromRack(i))
+                {
+                    const Tile &jokerTile = bestRound.getTile(i);
+                    Tile replacingTile(towupper(jokerTile.toChar()));
+#ifdef DEBUG
+                    cout << "helperSetRackRandom(): replacing Joker with "
+                         << convertToMb(replacingTile.toChar()) << endl;
+#endif
+                    // If the bag does not contain this letter anymore,
+                    // simply keep the joker in the rack.
+                    if (bag.in(replacingTile))
+                    {
+                        // The bag contains the replacing letter
+                        // We need to swap the joker (it is necessarily in the
+                        // new tiles, because jokerAdded is true)
+                        Rack tmpRack;
+                        pld.getNew(tmpRack);
+                        ASSERT(tmpRack.in(Tile::Joker()),
+                               "No joker found in the new tiles!");
+                        tmpRack.remove(Tile::Joker());
+                        tmpRack.add(replacingTile);
+                        pld.setNew(tmpRack);
+
+                        // Make sure the invariant is still correct, otherwise 
we keep the joker
+                        if (!pld.checkRack(min, min))
+                            pld = pldCopy;
+                    }
+                    break;
+                }
+            }
+        }
+    }
+
     // Shuffle the new tiles, to hide the order we imposed (joker first in a
     // joker game, then needed vowels, then needed consonants, and rest of the
     // rack)
@@ -331,12 +388,6 @@
     // Post-condition check. This should never fail, of course :)
     ASSERT(pld.checkRack(min, min), "helperSetRackRandom() is buggy!");
 
-#if 0
-    // Until now we didn't modify anything except local variables.
-    // Let's "commit" the changes
-    m_players[p]->setCurrentRack(pld);
-#endif
-
     return pld;
 }
 

Index: game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -b -r1.46 -r1.47
--- game.h      11 Jan 2009 14:20:35 -0000      1.46
+++ game.h      14 Jan 2009 21:53:38 -0000      1.47
@@ -75,7 +75,8 @@
     enum GameVariant
     {
         kNONE,      // Normal game rules
-        kJOKER      // Joker game
+        kJOKER,     // Joker game
+        kEXPLOSIVE  // "Explosive" game
     };
 
     /**

Index: public_game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/public_game.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- public_game.cpp     30 Nov 2008 20:53:44 -0000      1.1
+++ public_game.cpp     14 Jan 2009 21:53:38 -0000      1.2
@@ -59,6 +59,8 @@
 {
     if (iVariant == kJOKER)
         m_game.setVariant(Game::kJOKER);
+    else if (iVariant == kEXPLOSIVE)
+        m_game.setVariant(Game::kEXPLOSIVE);
     else
         m_game.setVariant(Game::kNONE);
 }

Index: public_game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/public_game.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- public_game.h       30 Nov 2008 20:53:44 -0000      1.1
+++ public_game.h       14 Jan 2009 21:53:38 -0000      1.2
@@ -84,7 +84,8 @@
     enum GameVariant
     {
         kNONE,      // Normal game rules
-        kJOKER      // Joker game
+        kJOKER,     // Joker game
+        kEXPLOSIVE  // "Explosive" game
     };
 
     /**

Index: results.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/results.h,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- results.h   22 Nov 2008 14:40:26 -0000      1.11
+++ results.h   14 Jan 2009 21:53:38 -0000      1.12
@@ -35,8 +35,9 @@
 /**
  * This class allows to perform a search on the board for a given rack,
  * and it offers accessors to the resulting rounds.
- * The rounds are sorted by decreasing number of points (but there is no
- * other ordering between 2 rounds with the same number of points).
+ * The rounds are sorted by decreasing number of points, then by alphabetical
+ * order (case insensitive), then by coordinates, then by alphabetical orderi
+ * again (case sensitive this time).
  */
 class Results
 {




reply via email to

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