eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot game/Makefile.am game/ai_percent.cpp game... [cppdic]


From: eliot-dev
Subject: [Eliot-dev] eliot game/Makefile.am game/ai_percent.cpp game... [cppdic]
Date: Thu, 20 Dec 2007 08:47:10 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         cppdic
Changes by:     Olivier Teulière <ipkiss>      07/12/20 08:47:10

Modified files:
        game           : Makefile.am ai_percent.cpp duplicate.cpp 
                         duplicate.h freegame.cpp game.cpp game.h 
                         game_factory.cpp game_factory.h game_io.cpp 
                         player.cpp player.h results.cpp results.h 
                         training.cpp training.h 
        test           : driver training_back.input training_back.ref 
        utils          : ncurses.cpp 
        wxwin          : mainframe.cc 
Added files:
        game           : settings.cpp settings.h 
        test           : duplicate_humans_ai.input 
                         duplicate_humans_ai.ref 

Log message:
         - New regression test for duplicate mode, involving human players
         - Player::endTurn() and Player::removeLastTurn() now take care of 
updating the player's score
         - Result indices are now unsigned
         - Forward declarations in game_factory.h
         - Removed duplicated code, added comments, and made the code slightly 
more robust (less dependent on m_currPlayer)
         - New Settings class: singleton centralizing the parameters of the game
         - Handled solo bonus in duplicate games, using configurable settings

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/Makefile.am?cvsroot=eliot&only_with_tag=cppdic&r1=1.13.2.3&r2=1.13.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/ai_percent.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.5.2.1&r2=1.5.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.16.2.2&r2=1.16.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.12.2.1&r2=1.12.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.18.2.5&r2=1.18.2.6
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.31.2.9&r2=1.31.2.10
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.29.2.6&r2=1.29.2.7
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_factory.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.8.2.3&r2=1.8.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_factory.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.8.2.3&r2=1.8.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_io.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.4.2.4&r2=1.4.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.14.2.2&r2=1.14.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.18.2.2&r2=1.18.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/results.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.10.2.2&r2=1.10.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/results.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.8.2.3&r2=1.8.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/training.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.17.2.3&r2=1.17.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/training.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.15&r2=1.15.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/settings.cpp?cvsroot=eliot&only_with_tag=cppdic&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/settings.h?cvsroot=eliot&only_with_tag=cppdic&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/test/driver?cvsroot=eliot&only_with_tag=cppdic&r1=1.5.2.2&r2=1.5.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/test/training_back.input?cvsroot=eliot&only_with_tag=cppdic&r1=1.1&r2=1.1.4.1
http://cvs.savannah.gnu.org/viewcvs/eliot/test/training_back.ref?cvsroot=eliot&only_with_tag=cppdic&r1=1.2&r2=1.2.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/test/duplicate_humans_ai.input?cvsroot=eliot&only_with_tag=cppdic&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/test/duplicate_humans_ai.ref?cvsroot=eliot&only_with_tag=cppdic&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/ncurses.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.22.2.10&r2=1.22.2.11
http://cvs.savannah.gnu.org/viewcvs/eliot/wxwin/mainframe.cc?cvsroot=eliot&only_with_tag=cppdic&r1=1.21.2.8&r2=1.21.2.9

Patches:
Index: game/Makefile.am
===================================================================
RCS file: /cvsroot/eliot/eliot/game/Makefile.am,v
retrieving revision 1.13.2.3
retrieving revision 1.13.2.4
diff -u -b -r1.13.2.3 -r1.13.2.4
--- game/Makefile.am    29 Nov 2007 19:09:56 -0000      1.13.2.3
+++ game/Makefile.am    20 Dec 2007 08:47:07 -0000      1.13.2.4
@@ -39,6 +39,7 @@
        rack.cpp rack.h                 \
        results.cpp results.h           \
        round.cpp round.h               \
+       settings.cpp settings.h         \
        training.cpp training.h         \
        turn.cpp turn.h                 \
        history.cpp history.h           \

Index: game/ai_percent.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/ai_percent.cpp,v
retrieving revision 1.5.2.1
retrieving revision 1.5.2.2
diff -u -b -r1.5.2.1 -r1.5.2.2
--- game/ai_percent.cpp 14 Dec 2007 18:12:32 -0000      1.5.2.1
+++ game/ai_percent.cpp 20 Dec 2007 08:47:07 -0000      1.5.2.2
@@ -59,7 +59,7 @@
     // 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;
+    unsigned int index = 0;
     while (index < m_results.size() &&
            m_results.get(index).getPoints() > wantedScore)
     {

Index: game/duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.16.2.2
retrieving revision 1.16.2.3
diff -u -b -r1.16.2.2 -r1.16.2.3
--- game/duplicate.cpp  17 Dec 2007 11:27:40 -0000      1.16.2.2
+++ game/duplicate.cpp  20 Dec 2007 08:47:07 -0000      1.16.2.3
@@ -17,6 +17,7 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include "duplicate.h"
 #include "dic.h"
 #include "tile.h"
 #include "rack.h"
@@ -25,16 +26,12 @@
 #include "results.h"
 #include "player.h"
 #include "ai_player.h"
-#include "duplicate.h"
+#include "settings.h"
 #include "debug.h"
 
 
-Duplicate::Duplicate(const Dictionary &iDic): Game(iDic)
-{
-}
-
-
-Duplicate::~Duplicate()
+Duplicate::Duplicate(const Dictionary &iDic)
+    : Game(iDic)
 {
 }
 
@@ -96,9 +93,9 @@
 {
     ASSERT(getNPlayers(), "Cannot start a game without any player");
 
+    // Arbitrary player, since they should all have the same rack
     m_currPlayer = 0;
 
-    /* XXX: code similar with endTurnForReal() */
     /* Complete the rack for the player that just played */
     int res = setRackRandom(m_currPlayer, true, RACK_NEW);
     /* End of the game? */
@@ -168,6 +165,7 @@
 
         /* Next turn */
         endTurnForReal();
+        start();
     }
 
     // XXX: check return code meaning
@@ -178,25 +176,17 @@
 void Duplicate::playRound(const Round &iRound, unsigned int p)
 {
     ASSERT(p < getNPlayers(), "Wrong player number");
-    Player *player = m_players[p];
 
-    /* Update the rack and the score of the current player */
-    player->addPoints(iRound.getPoints());
-    player->endTurn(iRound, m_history.getSize());
+    // Update the rack and the score of the playing player
+    m_players[p]->endTurn(iRound, m_history.getSize());
 
     m_hasPlayed[p] = true;
 }
 
 
-/*
- * This function really changes the turn, i.e. the best word is played and
- * a new rack is given to the players.
- * We suppose that all the players have finished to play for this turn (this
- * should have been checked by endturn())
- */
-int Duplicate::endTurnForReal()
+void Duplicate::endTurnForReal()
 {
-    /* Play the best word on the board */
+    // Find the player with the best score
     unsigned int imax = 0;
     for (unsigned int i = 1; i < getNPlayers(); i++)
     {
@@ -206,35 +196,48 @@
             imax = i;
         }
     }
-    m_currPlayer = imax;
-    helperPlayRound(m_players[imax]->getLastRound());
 
-    /* Complete the rack for the player that just played */
-    int res = setRackRandom(imax, true, RACK_NEW);
-    /* End of the game? */
-    if (res == 1)
+    // Handle solo bonus
+    // First check whetherf there are enough players in the game for the
+    // bonus to apply
+    int minNbPlayers = Settings::Instance().getInt("duplicate-solo-players");
+    if (getNPlayers() >= (unsigned int)minNbPlayers)
+    {
+        // Find whether other players than imax have the same score
+        bool otherWithSameScore = false;
+        for (unsigned int i = imax + 1; i < getNPlayers(); i++)
     {
-        end();
-        return 1;
+            if (m_players[i]->getLastRound().getPoints() >=
+                m_players[imax]->getLastRound().getPoints())
+            {
+                otherWithSameScore = true;
+                break;
+            }
+        }
+        if (!otherWithSameScore)
+        {
+            // Give the bonus to player imax
+            int bonus = Settings::Instance().getInt("duplicate-solo-value");
+            m_players[imax]->addPoints(bonus);
+            // TODO: keep a trace of the solo, so the interface
+            // can be aware of it...
     }
+    }
+
+    // Play the best word on the board
+    helperPlayRound(imax, m_players[imax]->getLastRound());
 
+    // Leave the same reliquate to all players
+    // This is required by the start() method which will be called to
+    // start the next turn
     const PlayedRack& pld = m_players[imax]->getCurrentRack();
-    /* All the players have the same rack */
     for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         if (i != imax)
         {
             m_players[i]->setCurrentRack(pld);
         }
-        /* Nobody has played yet in this round */
-        m_hasPlayed[i] = false;
     }
-
-    /* XXX: Little hack to handle the games with only AI players.
-     * This will have no effect when there is at least one human player */
-    endTurn();
-
-    return 0;
 }
 
 

Index: game/duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.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/duplicate.h    17 Dec 2007 11:27:41 -0000      1.12.2.1
+++ game/duplicate.h    20 Dec 2007 08:47:07 -0000      1.12.2.2
@@ -57,6 +57,12 @@
     /*************************
      * Game handling
      *************************/
+    /**
+     * In Duplicate mode, the start() method starts a new turn, and is
+     * automatically called when the previous turn is finished.
+     * It has an important pre-requisite: all the players must have the
+     * same rack when calling this function
+     */
     virtual int start();
     virtual int setRackRandom(unsigned int, bool, set_rack_mode);
     virtual int play(const wstring &iCoord, const wstring &iWord);
@@ -71,12 +77,21 @@
     void nextHumanPlayer();
 
 private:
-    // Private constructor and destructor to force using the GameFactory class
+    // Private constructor to force using the GameFactory class
     Duplicate(const Dictionary &iDic);
-    virtual ~Duplicate();
 
     void playRound(const Round &iRound, unsigned int p);
-    int  endTurnForReal();
+
+    /**
+     * This function really changes the turn, i.e. the best word is played,
+     * the game history is updated, a "solo" bonus is given if needed, and
+     * all racks are made equal to the one of the player which played the best
+     * move.
+     * We suppose here that all the players have finished to play for this turn
+     * (this should have been checked by endturn())
+     */
+    void endTurnForReal();
+
     void end();
     void duplicateAI(unsigned int p);
 

Index: game/freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.18.2.5
retrieving revision 1.18.2.6
diff -u -b -r1.18.2.5 -r1.18.2.6
--- game/freegame.cpp   17 Dec 2007 11:27:41 -0000      1.18.2.5
+++ game/freegame.cpp   20 Dec 2007 08:47:08 -0000      1.18.2.6
@@ -65,11 +65,10 @@
     }
 
     /* Update the rack and the score of the current player */
-    m_players[m_currPlayer]->addPoints(round.getPoints());
     m_players[m_currPlayer]->endTurn(round, m_history.getSize());
 
     /* Everything is OK, we can play the word */
-    helperPlayRound(round);
+    helperPlayRound(m_currPlayer, round);
 
     /* Next turn */
     // XXX: Should it be done by the interface instead?
@@ -96,10 +95,9 @@
     {
         const Round &round = player->getChosenRound();
         /* Update the rack and the score of the current player */
-        player->addPoints(round.getPoints());
         player->endTurn(round, m_history.getSize());
 
-        helperPlayRound(round);
+        helperPlayRound(p, round);
         endTurn();
     }
 }

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.31.2.9
retrieving revision 1.31.2.10
diff -u -b -r1.31.2.9 -r1.31.2.10
--- game/game.cpp       17 Dec 2007 11:27:41 -0000      1.31.2.9
+++ game/game.cpp       20 Dec 2007 08:47:08 -0000      1.31.2.10
@@ -63,7 +63,7 @@
 }
 
 
-void Game::helperPlayRound(const Round &iRound)
+void Game::helperPlayRound(unsigned int iPlayerId, const Round &iRound)
 {
     /*
      * We remove tiles from the bag only when they are played
@@ -73,8 +73,8 @@
      */
 
     // History of the game
-    m_history.setCurrentRack(getCurrentPlayer().getLastRack());
-    m_history.playRound(m_currPlayer, m_history.getSize(),  iRound);
+    m_history.setCurrentRack(getPlayer(iPlayerId).getLastRack());
+    m_history.playRound(iPlayerId, m_history.getSize(), iRound);
 
     debug("    helper: %d points\n",iRound.getPoints());
     m_points += iRound.getPoints();
@@ -106,12 +106,12 @@
                 // There is a big design problem here, but i am unsure what is
                 // the best way to fix it.
                 vector<Tile> tiles;
-                getPlayer(m_currPlayer).getCurrentRack().getAllTiles(tiles);
+                getPlayer(iPlayerId).getCurrentRack().getAllTiles(tiles);
                 for (unsigned int j = 0; j < tiles.size(); j++)
                 {
                     bag.replaceTile(tiles[j]);
                 }
-                getPlayer(m_currPlayer).getLastRack().getAllTiles(tiles);
+                getPlayer(iPlayerId).getLastRack().getAllTiles(tiles);
                 for (unsigned int j = 0; j < tiles.size(); j++)
                 {
                     bag.takeTile(tiles[j]);
@@ -179,11 +179,9 @@
             }
         }
         /* Remove the points of this round */
-        Player *player = m_players[m_currPlayer];
-        player->addPoints(- lastround.getPoints());
         m_points -= lastround.getPoints();
         /* Remove the turns */
-        player->removeLastTurn();
+        m_players[m_currPlayer]->removeLastTurn();
         m_history.removeLastTurn();
     }
     return 0;

Index: game/game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.29.2.6
retrieving revision 1.29.2.7
diff -u -b -r1.29.2.6 -r1.29.2.7
--- game/game.h 17 Dec 2007 11:27:41 -0000      1.29.2.6
+++ game/game.h 20 Dec 2007 08:47:08 -0000      1.29.2.7
@@ -219,7 +219,7 @@
      *********************************************************/
 
     /** Play a round on the board */
-    void helperPlayRound(const Round &iRound);
+    void helperPlayRound(unsigned int iPlayerId, const Round &iRound);
 
     /**
      * Set the rack randomly for the player p
@@ -261,6 +261,9 @@
      * The realBag is the current bag minus all the racks
      * present in the game. It represents the actual 
      * letters that are left in the bag.
+     * FIXME: in Duplicate mode, this method uses m_currPlayer to find the
+     * rack of the player. Since not all the players played the same word,
+     * it is important to set m_currPlayer accurately before!
      */
     void realBag(Bag &iBag) const;
 

Index: game/game_factory.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_factory.cpp,v
retrieving revision 1.8.2.3
retrieving revision 1.8.2.4
diff -u -b -r1.8.2.3 -r1.8.2.4
--- game/game_factory.cpp       21 Nov 2007 16:25:44 -0000      1.8.2.3
+++ game/game_factory.cpp       20 Dec 2007 08:47:08 -0000      1.8.2.4
@@ -17,14 +17,19 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include "config.h"
+
 #include <getopt.h>
 #include <string>
 #include <fstream>
 #include <exception>
 
-#include "config.h"
-#include "dic.h"
 #include "game_factory.h"
+#include "game.h"
+#include "training.h"
+#include "freegame.h"
+#include "duplicate.h"
+#include "dic.h"
 
 
 GameFactory *GameFactory::m_factory = NULL;

Index: game/game_factory.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_factory.h,v
retrieving revision 1.8.2.3
retrieving revision 1.8.2.4
diff -u -b -r1.8.2.3 -r1.8.2.4
--- game/game_factory.h 13 Dec 2007 12:11:07 -0000      1.8.2.3
+++ game/game_factory.h 20 Dec 2007 08:47:08 -0000      1.8.2.4
@@ -20,10 +20,15 @@
 #ifndef _GAME_FACTORY_H_
 #define _GAME_FACTORY_H_
 
-#include "game.h"
-#include "training.h"
-#include "freegame.h"
-#include "duplicate.h"
+#include <string>
+
+using std::string;
+
+class Dictionary;
+class Game;
+class Training;
+class FreeGame;
+class Duplicate;
 
 
 /**

Index: game/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_io.cpp,v
retrieving revision 1.4.2.4
retrieving revision 1.4.2.5
diff -u -b -r1.4.2.4 -r1.4.2.5
--- game/game_io.cpp    17 Dec 2007 11:27:41 -0000      1.4.2.4
+++ game/game_io.cpp    20 Dec 2007 08:47:08 -0000      1.4.2.5
@@ -32,6 +32,9 @@
 #include "player.h"
 #include "game.h"
 #include "game_factory.h"
+#include "training.h"
+#include "freegame.h"
+#include "duplicate.h"
 #include "encoding.h"
 #include "debug.h"
 
@@ -424,7 +427,7 @@
 //                     pGame->m_players[player]->endTurn(round,num - 1);
 
         // Play the round
-        pGame->helperPlayRound(round);
+        pGame->helperPlayRound(pGame->m_currPlayer, round);
     }
 
     /**************************************/

Index: game/player.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player.cpp,v
retrieving revision 1.14.2.2
retrieving revision 1.14.2.3
diff -u -b -r1.14.2.2 -r1.14.2.3
--- game/player.cpp     17 Dec 2007 11:27:41 -0000      1.14.2.2
+++ game/player.cpp     20 Dec 2007 08:47:08 -0000      1.14.2.3
@@ -63,11 +63,14 @@
 
 void Player::endTurn(const Round &iRound, unsigned int iTurn)
 {
+    addPoints(iRound.getPoints());
     m_history.playRound(m_id, iTurn, iRound);
 }
 
 void Player::removeLastTurn()
 {
+    // Remove points of the last turn
+    addPoints(- m_history.getPreviousTurn().getRound().getPoints());
     m_history.removeLastTurn();
 }
 

Index: game/player.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player.h,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/player.h       17 Dec 2007 11:27:41 -0000      1.18.2.2
+++ game/player.h       20 Dec 2007 08:47:08 -0000      1.18.2.3
@@ -65,8 +65,11 @@
     void addPoints(int iPoints) { m_score += iPoints; }
     int  getPoints() const      { return m_score; }
 
-    // Update the player "history", with the given round.
-    // A new rack is created with the remaining letters
+    /**
+     * Update the player "history", with the given round.
+     * A new rack is created with the remaining letters.
+     * The points of the rack are added to the player's score.
+     */
     void endTurn(const Round &iRound, unsigned int iTurn);
 
     wstring toString() const;

Index: game/results.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/results.cpp,v
retrieving revision 1.10.2.2
retrieving revision 1.10.2.3
diff -u -b -r1.10.2.2 -r1.10.2.3
--- game/results.cpp    17 Dec 2007 11:27:42 -0000      1.10.2.2
+++ game/results.cpp    20 Dec 2007 08:47:08 -0000      1.10.2.3
@@ -46,9 +46,9 @@
 };
 
 
-const Round & Results::get(int i) const
+const Round & Results::get(unsigned int i) const
 {
-    ASSERT(0 <= i && i < size(), "Results index out of bounds");
+    ASSERT(i < size(), "Results index out of bounds");
     return m_rounds[i];
 }
 

Index: game/results.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/results.h,v
retrieving revision 1.8.2.3
retrieving revision 1.8.2.4
diff -u -b -r1.8.2.3 -r1.8.2.4
--- game/results.h      17 Dec 2007 11:27:42 -0000      1.8.2.3
+++ game/results.h      20 Dec 2007 08:47:09 -0000      1.8.2.4
@@ -47,9 +47,9 @@
 class Results
 {
 public:
-    int size() const    { return m_rounds.size(); }
+    unsigned int size() const    { return m_rounds.size(); }
     void clear()        { m_rounds.clear(); }
-    const Round & get(int) const;
+    const Round & get(unsigned int) const;
 
     // Perform a search on the board
     void search(const Dictionary &iDic, Board &iBoard,

Index: game/training.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.cpp,v
retrieving revision 1.17.2.3
retrieving revision 1.17.2.4
diff -u -b -r1.17.2.3 -r1.17.2.4
--- game/training.cpp   17 Dec 2007 11:27:42 -0000      1.17.2.3
+++ game/training.cpp   20 Dec 2007 08:47:09 -0000      1.17.2.4
@@ -124,12 +124,12 @@
           convertToMb(round.getCoord().toString()).c_str(),
           round.getPoints());
 
-    m_players[m_currPlayer]->addPoints(round.getPoints());
-    // see game.cpp::helperPlayRound():99 comment
+    // Player::endTurn() must be called before Game::helperPlayRound().
+    // See the big comment in game.cpp, line 96
     m_players[m_currPlayer]->endTurn(round, m_history.getSize());
 
     /* Everything is OK, we can play the word */
-    helperPlayRound(round);
+    helperPlayRound(m_currPlayer, round);
 
     /* Next turn */
     endTurn();
@@ -167,18 +167,16 @@
 }
 
 
-int Training::playResult(int n)
+int Training::playResult(unsigned int n)
 {
-    Player *player = m_players[m_currPlayer];
     if (n >= m_results.size())
         return 2;
     const Round &round = m_results.get(n);
 
     /* Update the rack and the score of the current player */
-    player->addPoints(round.getPoints());
-    player->endTurn(round, m_history.getSize());
+    m_players[m_currPlayer]->endTurn(round, m_history.getSize());
 
-    helperPlayRound(round);
+    helperPlayRound(m_currPlayer, round);
     m_results.clear();
 
     /* Next turn */

Index: game/training.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.h,v
retrieving revision 1.15
retrieving revision 1.15.2.1
diff -u -b -r1.15 -r1.15.2.1
--- game/training.h     22 Jan 2006 12:23:53 -0000      1.15
+++ game/training.h     20 Dec 2007 08:47:09 -0000      1.15.2.1
@@ -51,7 +51,7 @@
     virtual int play(const wstring &iCoord, const wstring &iWord);
     virtual int endTurn();
     void search();
-    int playResult(int);
+    int playResult(unsigned int);
 
     int setRackRandom(bool, set_rack_mode);
     int setRackManual(bool iCheck, const wstring &iLetters);

Index: test/driver
===================================================================
RCS file: /cvsroot/eliot/eliot/test/driver,v
retrieving revision 1.5.2.2
retrieving revision 1.5.2.3
diff -u -b -r1.5.2.2 -r1.5.2.3
--- test/driver 4 Dec 2007 16:07:25 -0000       1.5.2.2
+++ test/driver 20 Dec 2007 08:47:09 -0000      1.5.2.3
@@ -53,6 +53,8 @@
 
 # 2 AI players
 duplicate_2_ai      5
+# 2 human players, one IA, with manual change of human player
+duplicate_humans_ai 6
 
 #################
 # Free game mode

Index: test/training_back.input
===================================================================
RCS file: /cvsroot/eliot/eliot/test/training_back.input,v
retrieving revision 1.1
retrieving revision 1.1.4.1
diff -u -b -r1.1 -r1.1.4.1
--- test/training_back.input    27 Dec 2005 01:04:49 -0000      1.1
+++ test/training_back.input    20 Dec 2007 08:47:10 -0000      1.1.4.1
@@ -9,17 +9,22 @@
 a r
 n 2
 a g
+a s
 n -1
+a s
 a g
 a p
 n -1
+a s
 a p
 a g
 a l
 n -1
+a s
 *
 r
 n 1
+a s
 a l
 a p
 q

Index: test/training_back.ref
===================================================================
RCS file: /cvsroot/eliot/eliot/test/training_back.ref,v
retrieving revision 1.2
retrieving revision 1.2.2.1
diff -u -b -r1.2 -r1.2.2.1
--- test/training_back.ref      1 Jan 2006 19:25:10 -0000       1.2
+++ test/training_back.ref      20 Dec 2007 08:47:10 -0000      1.2.2.1
@@ -40,7 +40,11 @@
  M   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  N   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
  O   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
+commande> a s
+116
 commande> n -1
+commande> a s
+80
 commande> a g
      1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
  A   -  -  -  -  -  -  -  -  -  -  -  -  -  -  -
@@ -72,6 +76,8 @@
 
 Rack 0: LMUAEYE
 commande> n -1
+commande> a s
+0
 commande> a p
 Eliot 1.5
 
@@ -105,9 +111,13 @@
  A B C D  E F G H I J K L M N O P Q R S T U V W X Y Z ?
  9 2 2 3 15 2 2 2 8 1 1 5 3 6 6 2 1 6 6 6 6 2 1 1 1 1 2
 commande> n -1
+commande> a s
+0
 commande> *
 commande> r
 commande> n 1
+commande> a s
+14
 commande> a l
  A B C D  E F G H I J K L M N O P Q R S T U V W X Y Z ?
  9 2 2 3 13 1 2 2 7 1 1 5 3 6 6 2 1 6 6 6 6 2 1 1 1 1 2

Index: utils/ncurses.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/ncurses.cpp,v
retrieving revision 1.22.2.10
retrieving revision 1.22.2.11
diff -u -b -r1.22.2.10 -r1.22.2.11
--- utils/ncurses.cpp   17 Dec 2007 11:27:42 -0000      1.22.2.10
+++ utils/ncurses.cpp   20 Dec 2007 08:47:10 -0000      1.22.2.11
@@ -316,10 +316,11 @@
     ioBox.draw(_("Search results"));
     ioBox.setDataSize(tr_game->getResults().size());
 
-    int i;
+    unsigned int i;
     const Results& res = tr_game->getResults();
     int x = ioBox.getLeft();
-    for (i = ioBox.getFirstLine(); i < res.size() && i < ioBox.getLastLine(); 
i++)
+    for (i = (unsigned int)ioBox.getFirstLine();
+         i < res.size() && i < (unsigned int)ioBox.getLastLine(); i++)
     {
         const Round &r = res.get(i);
         wstring coord = r.getCoord().toString();
@@ -329,7 +330,7 @@
                             convertToMb(coord).c_str());
     }
     // Complete the list with empty lines, to avoid trails
-    for (; i < ioBox.getLastLine(); i++)
+    for (; i < (unsigned int)ioBox.getLastLine(); i++)
     {
         ioBox.printDataLine(i, x + 1, string(ioBox.getWidth(), ' ').c_str());
     }

Index: wxwin/mainframe.cc
===================================================================
RCS file: /cvsroot/eliot/eliot/wxwin/mainframe.cc,v
retrieving revision 1.21.2.8
retrieving revision 1.21.2.9
diff -u -b -r1.21.2.8 -r1.21.2.9
--- wxwin/mainframe.cc  17 Dec 2007 11:27:43 -0000      1.21.2.8
+++ wxwin/mainframe.cc  20 Dec 2007 08:47:10 -0000      1.21.2.9
@@ -45,6 +45,7 @@
 
 #include "dic.h"
 #include "game.h"
+#include "training.h"
 #include "game_factory.h"
 #include "player.h"
 

Index: game/settings.cpp
===================================================================
RCS file: game/settings.cpp
diff -N game/settings.cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ game/settings.cpp   20 Dec 2007 08:47:09 -0000      1.1.2.1
@@ -0,0 +1,98 @@
+/*****************************************************************************
+ * Copyright (C) 2007 Eliot
+ * Authors: Olivier Teuliere  <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#include "settings.h"
+// TMP
+#include <stdlib.h>
+
+
+Settings *Settings::m_instance = NULL;
+
+
+Settings & Settings::Instance()
+{
+    if (m_instance == NULL)
+    {
+        m_instance = new Settings;
+    }
+    return *m_instance;
+}
+
+
+void Settings::Destroy()
+{
+    delete m_instance;
+    m_instance = NULL;
+}
+
+
+Settings::Settings()
+{
+    // Minimum number of players in a duplicate game needed to apply a "solo" 
bonus
+    // (16 is the ODS value)
+    m_intHandler.addOption("duplicate-solo-players", 16);
+    // Number of points granted for a solo (10 is the ODS value)
+    m_intHandler.addOption("duplicate-solo-value", 10);
+}
+
+
+void Settings::setInt(const string &iName, int iValue)
+{
+    m_intHandler.setOption(iName, iValue);
+}
+
+
+int Settings::getInt(const string &iName) const
+{
+    return m_intHandler.getOption(iName);
+}
+
+
+template <typename T>
+void Settings::OptionsHandler<T>::addOption(const string &iName, const T 
&iValue)
+{
+    m_options[iName] = iValue;
+}
+
+
+template <typename T>
+void Settings::OptionsHandler<T>::setOption(const string &iName, const T 
&iValue)
+{
+    typename map<string, T>::iterator it = m_options.find(iName);
+    if (it == m_options.end())
+    {
+        // FIXME: throw an exception object instead
+        throw 1;
+    }
+    it->second = iValue;
+}
+
+
+template <typename T>
+const T& Settings::OptionsHandler<T>::getOption(const string &iName) const
+{
+    typename map<string, T>::const_iterator it = m_options.find(iName);
+    if (it == m_options.end())
+    {
+        // FIXME: throw an exception object instead
+        throw 1;
+    }
+    return it->second;
+}
+

Index: game/settings.h
===================================================================
RCS file: game/settings.h
diff -N game/settings.h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ game/settings.h     20 Dec 2007 08:47:09 -0000      1.1.2.1
@@ -0,0 +1,106 @@
+/*****************************************************************************
+ * Copyright (C) 2007 Eliot
+ * Authors: Olivier Teuliere  <address@hidden>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *****************************************************************************/
+
+#ifndef _SETTINGS_H_
+#define _SETTINGS_H_
+
+#include <string>
+#include <map>
+
+using std::string;
+using std::map;
+
+
+/**
+ * This class centralizes the various configuration options of Eliot.
+ * It implements the Singleton pattern.
+ *
+ * Currently, there are few settings, and their initial value is hard-coded.
+ * In a later phase, this class will be able to export/import settings
+ * to/from a configuration file, and it should be possible to override
+ * configuration settings with settings given on the command-line (TODO).
+ * The boost::program_options library could be useful for this.
+ *
+ * This class will also be helpful for the "Settings" dialog box of the GUI.
+ */
+class Settings
+{
+public:
+    /// Access to the singleton
+    static Settings& Instance();
+    /// Destroy the singleton cleanly
+    static void Destroy();
+
+    void setInt(const string &iName, int iValue);
+    int getInt(const string &iName) const;
+
+
+private:
+
+    /**
+     * This nested class is simply there to handle storage and retrieval
+     * for options of a particular type (and factorize code)
+     */
+    template <typename T>
+    class OptionsHandler
+    {
+        public:
+            /// Set the value of an option
+            /**
+             * If the option already exists, its value is replaced,
+             * otherwise the option is created
+             */
+            void addOption(const string &iName, const T &iValue);
+
+            /**
+             * Change the value of an existing option.
+             * An exception is thrown if the option doesn't exist yet
+             */
+            void setOption(const string &iName, const T &iValue);
+
+            /**
+             * Query the value of an option.
+             * An exception is thrown if the option doesn't exist
+             */
+            const T& getOption(const string &iName) const;
+
+        private:
+            map<string, T> m_options;
+    };
+
+
+    /// Singleton instance
+    static Settings *m_instance;
+    Settings();
+
+    /// The settings can be of various types
+    OptionsHandler<bool> m_boolHandler;
+    OptionsHandler<int> m_intHandler;
+    // Add types as needed...
+
+};
+
+#endif
+
+/// Local Variables:
+/// mode: c++
+/// mode: hs-minor
+/// c-basic-offset: 4
+/// indent-tabs-mode: nil
+/// End:

Index: test/duplicate_humans_ai.input
===================================================================
RCS file: test/duplicate_humans_ai.input
diff -N test/duplicate_humans_ai.input
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test/duplicate_humans_ai.input      20 Dec 2007 08:47:09 -0000      1.1.2.1
@@ -0,0 +1,19 @@
+d 2 1
+a T
+j DOSAIT H4
+j DOSAIT h5
+a S
+a T
+n 1
+j MoTIVE 11F
+a S
+j VIDaME G6
+a S
+j FINASSE 12C
+j FANS i6
+a S
+a t
+a gm
+a p
+q
+q

Index: test/duplicate_humans_ai.ref
===================================================================
RCS file: test/duplicate_humans_ai.ref
diff -N test/duplicate_humans_ai.ref
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ test/duplicate_humans_ai.ref        20 Dec 2007 08:47:10 -0000      1.1.2.1
@@ -0,0 +1,76 @@
+[?] pour l'aide
+commande> d 2 1
+mode duplicate
+[?] pour l'aide
+commande> a T
+Joueur 0: DYSIATO
+Joueur 1: DYSIATO
+Joueur 2: DYSIATO
+commande> j DOSAIT H4
+commande> j DOSAIT h5
+commande> a S
+Joueur 0:   18
+Joueur 1:   14
+Joueur 2:   30
+commande> a T
+Joueur 0: DIEF?MV
+Joueur 1: DIEF?MV
+Joueur 2: DIEF?MV
+commande> n 1
+commande> j MoTIVE 11F
+commande> a S
+Joueur 0:   18
+Joueur 1:   32
+Joueur 2:   30
+commande> j VIDaME G6
+commande> a S
+Joueur 0:   47
+Joueur 1:   32
+Joueur 2:   59
+commande> j FINASSE 12C
+commande> j FANS i6
+commande> a S
+Joueur 0:   78
+Joueur 1:   57
+Joueur 2:   94
+commande> a t
+UFEQBZS
+commande> a gm
+     1  2  3  4  5  6  7  8  9 10 11 12 13 14 15
+ A   @  -  -  +  -  -  -  @  -  -  -  +  -  -  @
+ B   -  #  -  -  -  *  -  -  -  *  -  -  -  #  -
+ C   -  -  #  -  -  -  +  -  +  -  -  -  #  -  -
+ D   +  -  -  #  -  -  -  +  -  -  -  #  -  -  +
+ E   -  -  -  -  #  -  -  -  -  -  #  -  -  -  -
+ F   -  *  -  -  -  *  -  -  -  *  -  -  -  *  -
+ G   -  -  +  -  -  V  I  D  a  M  E  -  +  -  -
+ H   F  A  I  N  E  S  -  O  Y  A  T  S  -  -  @
+ I   -  -  +  -  -  -  +  -  +  -  -  -  +  -  -
+ J   -  *  -  -  -  *  -  -  -  *  -  -  -  *  -
+ K   -  -  -  -  #  -  -  -  -  -  #  -  -  -  -
+ L   +  -  -  #  -  -  -  +  -  -  -  #  -  -  +
+ M   -  -  #  -  -  -  +  -  +  -  -  -  #  -  -
+ N   -  #  -  -  -  *  -  -  -  *  -  -  -  #  -
+ O   @  -  -  +  -  -  -  @  -  -  -  +  -  -  @
+commande> a p
+Eliot 1.5
+
+Game type: Duplicate
+Player 0: Human
+Player 1: Human
+Player 2: Computer
+
+    N |   RACK   |    SOLUTION     | REF | PTS | P | BONUS
+   ===|==========|=================|=====|=====|===|======
+    1 |  DYSIATO | OYATS           |  H8 |  30 | 2 |  
+    2 | DI+EF?MV | VIDaME          |  G6 |  29 | 0 |  
+    3 | F+USIENA | FAINES          |  H1 |  35 | 2 |  
+
+   Total: 94
+
+Rack 0: U+FEQBZS
+Rack 1: U+FEQBZS
+Rack 2: U+FEQBZS
+commande> q
+fin du mode duplicate
+commande> q




reply via email to

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