eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot game/ai_percent.cpp game/ai_percent.h gam... [cppdic]


From: eliot-dev
Subject: [Eliot-dev] eliot game/ai_percent.cpp game/ai_percent.h gam... [cppdic]
Date: Fri, 14 Dec 2007 18:12:33 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         cppdic
Changes by:     Olivier Teulière <ipkiss>      07/12/14 18:12:33

Modified files:
        game           : ai_percent.cpp ai_percent.h freegame.cpp 
                         game.cpp game.h pldrack.cpp pldrack.h 
        test           : freegame_passing.input freegame_passing.ref 

Log message:
         - In the AIPercent class, the percentage is now a percentage of the 
best score, instead of a percentage of the index in the results array, (which 
was not interesting)
         - According to the rules in the ODS, it is allowed to pass (without 
changing any letter) even if there are less than 7 letters in the bag. Freegame 
now respects this, and the regression test has been updated accordingly
         - Some simplifications ans cosmetic changes

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/ai_percent.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.5&r2=1.5.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/ai_percent.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.6&r2=1.6.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.18.2.2&r2=1.18.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.31.2.6&r2=1.31.2.7
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.29.2.4&r2=1.29.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.2.1&r2=1.9.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.12.2.1&r2=1.12.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/test/freegame_passing.input?cvsroot=eliot&only_with_tag=cppdic&r1=1.1&r2=1.1.6.1
http://cvs.savannah.gnu.org/viewcvs/eliot/test/freegame_passing.ref?cvsroot=eliot&only_with_tag=cppdic&r1=1.3&r2=1.3.2.1

Patches:
Index: game/ai_percent.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/ai_percent.cpp,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -b -r1.5 -r1.5.2.1
--- game/ai_percent.cpp 1 Jan 2006 19:49:35 -0000       1.5
+++ game/ai_percent.cpp 14 Dec 2007 18:12:32 -0000      1.5.2.1
@@ -55,7 +55,23 @@
 
 const Round & AIPercent::getChosenRound() const
 {
-    int index = (int)(m_percent * (m_results.size() - 1));
+    double wantedScore = m_percent * m_results.get(0).getPoints();
+    // Look for the first round giving at least 'wantedScore' points
+    // Browse the results 10 by 10 (a dichotomy would be better, but this
+    // is not performance critical)
+    int index = 0;
+    while (index < m_results.size() &&
+           m_results.get(index).getPoints() > wantedScore)
+    {
+        index += 10;
+    }
+    // Now the wanted round is in the last 10 indices
+    if (index >= m_results.size())
+        index = m_results.size() - 1;
+    while (m_results.get(index).getPoints() < wantedScore)
+    {
+        --index;
+    }
     return m_results.get(index);
 }
 

Index: game/ai_percent.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/ai_percent.h,v
retrieving revision 1.6
retrieving revision 1.6.2.1
diff -u -b -r1.6 -r1.6.2.1
--- game/ai_percent.h   1 Jan 2006 19:49:35 -0000       1.6
+++ game/ai_percent.h   14 Dec 2007 18:12:32 -0000      1.6.2.1
@@ -27,10 +27,10 @@
  * This kind of AI is parameterized by a percentage p.
  * The computation consists in finding all the N possible rounds for the
  * current rack/board, and sorting the list.
- * The chosen round is the n'th element of the sorted list, such that n/N
- * is closest to the percentage p.
- * A percentage of 0 should always return the best round (i.e. the one with
- * the highest score), while a percentage of 1 should return the worst one.
+ * The chosen round is the one with the smallest score at least equal to
+ * p * best_score.
+ * A percentage of 1 should always return the best round (i.e. the one with
+ * the highest score), while a percentage of 0 should return the worst one.
  * This kind of AI will never change letters (unless it cannot play anything,
  * in which case it just passes without changing letters).
  */

Index: game/freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.18.2.2
retrieving revision 1.18.2.3
diff -u -b -r1.18.2.2 -r1.18.2.3
--- game/freegame.cpp   4 Dec 2007 16:07:25 -0000       1.18.2.2
+++ game/freegame.cpp   14 Dec 2007 18:12:32 -0000      1.18.2.3
@@ -221,10 +221,11 @@
     ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
 
     // It is forbidden to change letters when the bag does not contain at
-    // least 7 letters (this is explicitely stated in the ODS).
+    // least 7 letters (this is explicitly stated in the ODS). But it is
+    // still allowed to pass
     Bag bag(m_dic);
     realBag(bag);
-    if (bag.nTiles() < 7)
+    if (bag.nTiles() < 7 && !iToChange.empty())
     {
         return 1;
     }

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.31.2.6
retrieving revision 1.31.2.7
diff -u -b -r1.31.2.6 -r1.31.2.7
--- game/game.cpp       5 Dec 2007 10:36:00 -0000       1.31.2.6
+++ game/game.cpp       14 Dec 2007 18:12:32 -0000      1.31.2.7
@@ -359,6 +359,8 @@
 
         // 3) Complete the rack normally... but without any joker!
         Tile l;
+        // FIXME: this can be an infinite loop if the only tile left in the
+        // bag is a joker!
         while (bag.nTiles() != 0 && pld.nTiles() != RACK_SIZE)
         {
             l = bag.selectRandom();
@@ -473,7 +475,7 @@
 
 void Game::addAIPlayer()
 {
-    m_players.push_back(new AIPercent(getNPlayers(), 0));
+    m_players.push_back(new AIPercent(getNPlayers(), 1));
 }
 
 

Index: game/game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.29.2.4
retrieving revision 1.29.2.5
diff -u -b -r1.29.2.4 -r1.29.2.5
--- game/game.h 4 Dec 2007 16:07:25 -0000       1.29.2.4
+++ game/game.h 14 Dec 2007 18:12:32 -0000      1.29.2.5
@@ -94,10 +94,11 @@
     /**
      * Eliot file formats
      */
-    typedef enum {
+    enum game_file_format
+    {
       FILE_FORMAT_STANDARD,
       FILE_FORMAT_ADVANCED
-    } game_file_format;
+    };
 
     /**
      * Saved games handling.
@@ -116,7 +117,7 @@
      * Saving can be forced to advanced format for training games by 
      * setting the last parameter to FILE_FORMAT_ADVANCED
      */
-    void save(ostream &out, game_file_format format=FILE_FORMAT_STANDARD) 
const;
+    void save(ostream &out, game_file_format format = FILE_FORMAT_STANDARD) 
const;
 
     /*************************
      * Playing the game
@@ -127,11 +128,10 @@
     /*************************
      * Set the rack for searching
      *
-     * The int parameter is a boolean, if this parameter
-     * set the rack will check that there are at least
+     * If 'check' is true, the rack will check that there are at least
      * 2 vowels and 2 consonants before the round 15.
      *
-     * The setrackmanual parameter string has to contain
+     * The 'str' parameter has to contain
      * 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '?'
      *
      * return value

Index: game/pldrack.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.cpp,v
retrieving revision 1.9.2.1
retrieving revision 1.9.2.2
diff -u -b -r1.9.2.1 -r1.9.2.2
--- game/pldrack.cpp    27 Nov 2007 18:01:06 -0000      1.9.2.1
+++ game/pldrack.cpp    14 Dec 2007 18:12:33 -0000      1.9.2.2
@@ -32,10 +32,11 @@
 
 
 PlayedRack::PlayedRack()
+    : m_reject(false)
 {
-  reject = false;
 }
 
+
 void PlayedRack::addOld(const Tile &t)
 {
     m_oldTiles.push_back(t);
@@ -51,26 +52,22 @@
 void PlayedRack::getOldTiles(vector<Tile> &oTiles) const
 {
     oTiles.clear();
-    for (int i = 0; i < nOld(); i++)
-        oTiles.push_back(m_oldTiles[i]);
+    oTiles = m_oldTiles;
 }
 
 
 void PlayedRack::getNewTiles(vector<Tile> &oTiles) const
 {
     oTiles.clear();
-    for (int i = 0; i < nNew(); i++)
-        oTiles.push_back(m_newTiles[i]);
+    oTiles = m_newTiles;
 }
 
 
 void PlayedRack::getAllTiles(vector<Tile> &oTiles) const
 {
     oTiles.clear();
-    for (int i = 0; i < nOld(); i++)
-        oTiles.push_back(m_oldTiles[i]);
-    for (int j = 0; j < nNew(); j++)
-        oTiles.push_back(m_newTiles[j]);
+    oTiles = m_oldTiles;
+    oTiles.insert(oTiles.end(), m_newTiles.begin(), m_newTiles.end());
 }
 
 
@@ -122,19 +119,18 @@
 
 void PlayedRack::setOld(const Rack &iRack)
 {
-    vector<Tile> l;
-    iRack.getTiles(l);
-    m_oldTiles = l;
+    m_oldTiles.clear();
+    iRack.getTiles(m_oldTiles);
 }
 
 
 void PlayedRack::setNew(const Rack &iRack)
 {
-    vector<Tile> l;
-    iRack.getTiles(l);
-    m_newTiles = l;
+    m_newTiles.clear();
+    iRack.getTiles(m_newTiles);
 }
 
+
 int PlayedRack::setManual(const wstring& iLetters)
 {
     unsigned int i;
@@ -171,6 +167,7 @@
     return 0;
 }
 
+
 bool PlayedRack::checkRack(int cMin, int vMin) const
 {
     vector<Tile>::const_iterator it;
@@ -214,7 +211,7 @@
         s += L"+";
     }
 
-    if (mode > RACK_EXTRA  && reject)
+    if (mode > RACK_EXTRA  && m_reject)
     {
         s += L"-";
         // new rack: reject

Index: game/pldrack.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.h,v
retrieving revision 1.12.2.1
retrieving revision 1.12.2.2
diff -u -b -r1.12.2.1 -r1.12.2.2
--- game/pldrack.h      13 Dec 2007 12:11:07 -0000      1.12.2.1
+++ game/pldrack.h      14 Dec 2007 18:12:33 -0000      1.12.2.2
@@ -82,7 +82,7 @@
     wstring toString(display_mode iShowExtraSigns = RACK_EXTRA) const;
 
 private:
-    bool reject;
+    bool m_reject;
     vector<Tile> m_oldTiles;
     vector<Tile> m_newTiles;
 };

Index: test/freegame_passing.input
===================================================================
RCS file: /cvsroot/eliot/eliot/test/freegame_passing.input,v
retrieving revision 1.1
retrieving revision 1.1.6.1
diff -u -b -r1.1 -r1.1.6.1
--- test/freegame_passing.input 16 Apr 2005 15:47:59 -0000      1.1
+++ test/freegame_passing.input 14 Dec 2007 18:12:33 -0000      1.1.6.1
@@ -2,6 +2,9 @@
 a S
 p
 p
+a t
+p UIET
+a t
 p
 p
 p
@@ -22,6 +25,8 @@
 p
 p
 p
+a S
+a T
 a p
 q
 q

Index: test/freegame_passing.ref
===================================================================
RCS file: /cvsroot/eliot/eliot/test/freegame_passing.ref,v
retrieving revision 1.3
retrieving revision 1.3.2.1
diff -u -b -r1.3 -r1.3.2.1
--- test/freegame_passing.ref   1 Jan 2006 19:25:10 -0000       1.3
+++ test/freegame_passing.ref   14 Dec 2007 18:12:33 -0000      1.3.2.1
@@ -7,6 +7,11 @@
 Joueur 1:    0
 commande> p
 commande> p
+commande> a t
+EGISSTU
+commande> p UIET
+commande> a t
+GSSDIDB
 commande> p
 commande> p
 commande> p
@@ -27,6 +32,12 @@
 commande> p
 commande> p
 commande> p
+commande> a S
+Joueur 0:  -12
+Joueur 1:  836
+commande> a T
+Joueur 0: BDDGISS
+Joueur 1: 
 commande> a p
 Eliot 1.5
 
@@ -39,25 +50,31 @@
     1 |  RENLOHL | HERON           |  H4 |  24 | 1 |  
     2 | LL+XUORC | OCREUX          |  5E |  34 | 1 |  
     3 | LL+NAECT | CALLENT         |  I7 |  73 | 1 | *
-    4 |  DIBB?EM | BIBENDuM        | 12E |  78 | 1 | *
-    5 |  TOEOMLZ | TOMIEZ          |  F9 |  38 | 1 |  
-    6 | LO+ESLSI | SOLEILS         |  M6 |  73 | 1 | *
-    7 |  UEGTVAW | VAGUEZ          | 14A |  38 | 1 |  
-    8 | TW+LAEPU | PAVE            | A12 |  36 | 1 |  
-    9 | LTUW+FAA | FATWA           |  N2 |  42 | 1 |  
-   10 | LU+JAEYU | LAYE            |  O1 |  61 | 1 |  
-   11 | JUU+SENI | JEUNE           | H11 |  47 | 1 |  
-   12 | ISU+RMPN | SPRAY           |  3K |  32 | 1 |  
-   13 | IMNU+AIV | VLAN            |  8L |  33 | 1 |  
-   14 | IIMU+UQE | QUI             | B10 |  30 | 1 |  
-   15 | EIMU+RNF | UNIFORME        |  E1 |  62 | 1 | *
-   16 |  ODITREE | ETOURDIE        |  1B |  80 | 1 | *
-   17 |  TEN?IKR | jERKE           |  8A |  69 | 1 |  
+    4 |  ?EMTOEO | ENTOlOME        | 12H |  70 | 1 | *
+    5 |  MLZESLS | MEZES           | O11 |  45 | 1 |  
+    6 | LLS+IUEG | GOUILLES        |  E4 |  68 | 1 | *
+    7 |  TVAWLAE | AWELE           | 10A |  34 | 1 |  
+    8 | ATV+PUFA | PAVAT           |  A7 |  30 | 1 |  
+    9 | AFU+AIAE | FA              |  G7 |  24 | 1 |  
+   10 | AAEIU+YU | YEUX            |  J2 |  42 | 1 |  
+   11 | AAIU+TEN | NEZ             | 13M |  31 | 1 |  
+   12 | AAITU+IR | AUTRE           | 14K |  21 | 1 |  
+   13 | AII+MPNA | PAMAI           | 15G |  26 | 1 |  
+   14 | IN+IUURE | TUNES           | 11A |  20 | 1 |  
+   15 | IIRU+RNF | NIF             | 11K |  24 | 1 |  
+   16 | IRRU+OEI | HOUER           |  4H |  18 | 1 |  
+   17 | IIRU+TSE | YETIS           |  2J |  28 | 1 |  
+   18 | IRU+ETHO | HERE            |  3I |  27 | 1 |  
+   19 | IOTU+?JN | SUJeTION        |  N2 |  66 | 1 | *
+   20 |  SEVDQIR | DEVENIRS        |  C7 |  36 | 1 |  
+   21 | Q+BAKIAE | KABIG           |  4A |  54 | 1 |  
+   22 |      AEQ | QUE             |  6D |  18 | 1 |  
+   23 |        A | KA              |  A4 |  11 | 1 |  
 
-   Total: 850
+   Total: 824
 
-Rack 0: EGISSTU
-Rack 1: INT+ESDO
+Rack 0: BDDGISS
+Rack 1: 
 commande> q
 fin du mode partie libre
 commande> q




reply via email to

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