eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot game/bag.h game/board.cpp game/coord.h ga... [cppdic]


From: eliot-dev
Subject: [Eliot-dev] eliot game/bag.h game/board.cpp game/coord.h ga... [cppdic]
Date: Mon, 17 Dec 2007 11:27:43 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         cppdic
Changes by:     Olivier Teulière <ipkiss>      07/12/17 11:27:43

Modified files:
        game           : bag.h board.cpp coord.h duplicate.cpp 
                         duplicate.h freegame.cpp freegame.h game.cpp 
                         game.h game_io.cpp history.cpp history.h 
                         player.cpp player.h pldrack.cpp pldrack.h 
                         results.cpp results.h round.cpp round.h 
                         training.cpp turn.cpp turn.h 
        utils          : game_io.cpp ncurses.cpp 
        wxwin          : mainframe.cc 

Log message:
         - Check the letters against the dictionary when the user plays a word
         - Added (or updated) many comments
         - Made some constructors explicit to avoid bad surprises
         - Players numbers, round indices and turns are now of type "unsigned 
int" instead of "int"
         - Other cosmetic changes

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/bag.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.8.2.2&r2=1.8.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/board.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.14.2.4&r2=1.14.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/coord.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.7.2.1&r2=1.7.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.16.2.1&r2=1.16.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.12&r2=1.12.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.18.2.4&r2=1.18.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.11&r2=1.11.2.1
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.31.2.8&r2=1.31.2.9
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.29.2.5&r2=1.29.2.6
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_io.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.4.2.3&r2=1.4.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/history.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/history.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.11.2.1&r2=1.11.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.14.2.1&r2=1.14.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.18.2.1&r2=1.18.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.2.2&r2=1.9.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.12.2.2&r2=1.12.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/results.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.10.2.1&r2=1.10.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/results.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.8.2.2&r2=1.8.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/round.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.10.2.3&r2=1.10.2.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/round.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/training.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.17.2.2&r2=1.17.2.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.11.2.1&r2=1.11.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn.h?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.2.1&r2=1.9.2.2
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/game_io.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.9.2.4&r2=1.9.2.5
http://cvs.savannah.gnu.org/viewcvs/eliot/utils/ncurses.cpp?cvsroot=eliot&only_with_tag=cppdic&r1=1.22.2.9&r2=1.22.2.10
http://cvs.savannah.gnu.org/viewcvs/eliot/wxwin/mainframe.cc?cvsroot=eliot&only_with_tag=cppdic&r1=1.21.2.7&r2=1.21.2.8

Patches:
Index: game/bag.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/bag.h,v
retrieving revision 1.8.2.2
retrieving revision 1.8.2.3
diff -u -b -r1.8.2.2 -r1.8.2.3
--- game/bag.h  27 Nov 2007 18:01:05 -0000      1.8.2.2
+++ game/bag.h  17 Dec 2007 11:27:40 -0000      1.8.2.3
@@ -35,7 +35,7 @@
 class Bag
 {
 public:
-    Bag(const Dictionary &iDic);
+    explicit Bag(const Dictionary &iDic);
 
     /// Take a tile in the bag
     void takeTile(const Tile &iTile);

Index: game/board.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/board.cpp,v
retrieving revision 1.14.2.4
retrieving revision 1.14.2.5
diff -u -b -r1.14.2.4 -r1.14.2.5
--- game/board.cpp      27 Nov 2007 18:01:05 -0000      1.14.2.4
+++ game/board.cpp      17 Dec 2007 11:27:40 -0000      1.14.2.5
@@ -154,13 +154,12 @@
 void Board::addRound(const Dictionary &iDic, const Round &iRound)
 {
     Tile t;
-    int row, col;
 
-    row = iRound.getCoord().getRow();
-    col = iRound.getCoord().getCol();
+    int row = iRound.getCoord().getRow();
+    int col = iRound.getCoord().getCol();
     if (iRound.getCoord().getDir() == Coord::HORIZONTAL)
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (m_tilesRow[row][col + i].isEmpty())
             {
@@ -174,7 +173,7 @@
     }
     else
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (m_tilesRow[row + i][col].isEmpty())
             {
@@ -195,13 +194,11 @@
 
 void Board::removeRound(const Dictionary &iDic, const Round &iRound)
 {
-    int row, col;
-
-    row = iRound.getCoord().getRow();
-    col = iRound.getCoord().getCol();
+    int row = iRound.getCoord().getRow();
+    int col = iRound.getCoord().getCol();
     if (iRound.getCoord().getDir() == Coord::HORIZONTAL)
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (iRound.isPlayedFromRack(i))
             {
@@ -216,7 +213,7 @@
     }
     else
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (iRound.isPlayedFromRack(i))
             {
@@ -246,17 +243,15 @@
                          bool firstturn)
 {
     Tile t;
-    int row, col, i;
-    int l, p, fromrack;
-    int pts, ptscross, wordmul;
+    int l, p;
     bool isolated = true;
 
-    fromrack = 0;
-    pts = 0;
-    ptscross = 0;
-    wordmul = 1;
-    row = iRound.getCoord().getRow();
-    col = iRound.getCoord().getCol();
+    int fromrack = 0;
+    int pts = 0;
+    int ptscross = 0;
+    int wordmul = 1;
+    int row = iRound.getCoord().getRow();
+    int col = iRound.getCoord().getCol();
 
     /* Is the word an extension of another word? */
     if (!iTilesMx[row][col - 1].isEmpty() ||
@@ -265,7 +260,7 @@
         return 1;
     }
 
-    for (i = 0; i < iRound.getWordLen(); i++)
+    for (unsigned int i = 0; i < iRound.getWordLen(); i++)
     {
         t = iRound.getTile(i);
         if (!iTilesMx[row][col + i].isEmpty())
@@ -383,13 +378,12 @@
 void Board::testRound(const Round &iRound)
 {
     Tile t;
-    int row, col;
 
-    row = iRound.getCoord().getRow();
-    col = iRound.getCoord().getCol();
+    int row = iRound.getCoord().getRow();
+    int col = iRound.getCoord().getCol();
     if (iRound.getCoord().getDir() == Coord::HORIZONTAL)
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (m_tilesRow[row][col + i].isEmpty())
             {
@@ -405,7 +399,7 @@
     }
     else
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (m_tilesRow[row + i][col].isEmpty())
             {

Index: game/coord.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/coord.h,v
retrieving revision 1.7.2.1
retrieving revision 1.7.2.2
diff -u -b -r1.7.2.1 -r1.7.2.2
--- game/coord.h        13 Dec 2007 12:11:07 -0000      1.7.2.1
+++ game/coord.h        17 Dec 2007 11:27:40 -0000      1.7.2.2
@@ -27,16 +27,22 @@
 #ifndef _COORD_H
 #define _COORD_H
 
-using std::string;
+#include <string>
+
 using std::wstring;
 
+
+/**
+ * This class handles coordinates of a square on the board.
+ * The row and column start at 1.
+ */
 class Coord
 {
 public:
 
     enum Direction {VERTICAL, HORIZONTAL};
 
-    // Construction, destruction
+    // Construction
     Coord(int iRow = -1, int iCol = -1, Direction iDir = HORIZONTAL);
     Coord(const wstring &iStr);
 

Index: game/duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.16.2.1
retrieving revision 1.16.2.2
diff -u -b -r1.16.2.1 -r1.16.2.2
--- game/duplicate.cpp  4 Dec 2007 16:07:24 -0000       1.16.2.1
+++ game/duplicate.cpp  17 Dec 2007 11:27:40 -0000      1.16.2.2
@@ -39,7 +39,7 @@
 }
 
 
-int Duplicate::setRackRandom(int p, bool iCheck, set_rack_mode mode)
+int Duplicate::setRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
 {
     int res;
     do
@@ -71,12 +71,12 @@
 }
 
 
-void Duplicate::duplicateAI(int n)
+void Duplicate::duplicateAI(unsigned int p)
 {
-    ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
-    ASSERT(!m_players[n]->isHuman(), "AI requested for a human player");
+    ASSERT(p < getNPlayers(), "Wrong player number");
+    ASSERT(!m_players[p]->isHuman(), "AI requested for a human player");
 
-    AIPlayer *player = static_cast<AIPlayer*>(m_players[n]);
+    AIPlayer *player = static_cast<AIPlayer*>(m_players[p]);
     player->compute(m_dic, m_board, m_history.getSize());
 
     if (player->changesLetters())
@@ -87,7 +87,7 @@
     }
     else
     {
-        playRound(player->getChosenRound(), n);
+        playRound(player->getChosenRound(), p);
     }
 }
 
@@ -110,7 +110,7 @@
 
     const PlayedRack& pld = m_players[m_currPlayer]->getCurrentRack();
     /* All the players have the same rack */
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         if (i != m_currPlayer)
         {
@@ -142,7 +142,7 @@
  */
 int Duplicate::endTurn()
 {
-    int i;
+    unsigned int i;
     for (i = 0; i < getNPlayers(); i++)
     {
         if (m_players[i]->isHuman() && !m_hasPlayed[i])
@@ -175,16 +175,16 @@
 }
 
 
-void Duplicate::playRound(const Round &iRound, int n)
+void Duplicate::playRound(const Round &iRound, unsigned int p)
 {
-    ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
-    Player *player = m_players[n];
+    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());
 
-    m_hasPlayed[n] = true;
+    m_hasPlayed[p] = true;
 }
 
 
@@ -196,11 +196,9 @@
  */
 int Duplicate::endTurnForReal()
 {
-    int res, i, imax;
-
     /* Play the best word on the board */
-    imax = 0;
-    for (i = 1; i < getNPlayers(); i++)
+    unsigned int imax = 0;
+    for (unsigned int i = 1; i < getNPlayers(); i++)
     {
         if (m_players[i]->getLastRound().getPoints() >
             m_players[imax]->getLastRound().getPoints())
@@ -212,7 +210,7 @@
     helperPlayRound(m_players[imax]->getLastRound());
 
     /* Complete the rack for the player that just played */
-    res = setRackRandom(imax, true, RACK_NEW);
+    int res = setRackRandom(imax, true, RACK_NEW);
     /* End of the game? */
     if (res == 1)
     {
@@ -222,7 +220,7 @@
 
     const PlayedRack& pld = m_players[imax]->getCurrentRack();
     /* All the players have the same rack */
-    for (i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         if (i != imax)
         {
@@ -246,15 +244,15 @@
 }
 
 
-int Duplicate::setPlayer(int n)
+int Duplicate::setPlayer(unsigned int p)
 {
-    ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
+    ASSERT(p < getNPlayers(), "Wrong player number");
 
     /* Forbid switching to an AI player */
-    if (!m_players[n]->isHuman())
+    if (!m_players[p]->isHuman())
         return 1;
 
-    m_currPlayer = n;
+    m_currPlayer = p;
     return 0;
 }
 

Index: game/duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.h,v
retrieving revision 1.12
retrieving revision 1.12.2.1
diff -u -b -r1.12 -r1.12.2.1
--- game/duplicate.h    22 Jan 2006 12:23:53 -0000      1.12
+++ game/duplicate.h    17 Dec 2007 11:27:41 -0000      1.12.2.1
@@ -58,14 +58,16 @@
      * Game handling
      *************************/
     virtual int start();
-    virtual int setRackRandom(int, bool, set_rack_mode);
+    virtual int setRackRandom(unsigned int, bool, set_rack_mode);
     virtual int play(const wstring &iCoord, const wstring &iWord);
     virtual int endTurn();
 
-    int setPlayer(int);
-    // Switch to the previous human player who has not played yet
+    int setPlayer(unsigned int);
+
+    /// Switch to the previous human player who has not played yet
     void prevHumanPlayer();
-    // Switch to the next human player who has not played yet
+
+    /// Switch to the next human player who has not played yet
     void nextHumanPlayer();
 
 private:
@@ -73,10 +75,10 @@
     Duplicate(const Dictionary &iDic);
     virtual ~Duplicate();
 
-    void playRound(const Round &iRound, int n);
+    void playRound(const Round &iRound, unsigned int p);
     int  endTurnForReal();
     void end();
-    void duplicateAI(int n);
+    void duplicateAI(unsigned int p);
 
     // m_hasPlayed[p] is true iff player p has played for this turn
     map<int, bool> m_hasPlayed;

Index: game/freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.18.2.4
retrieving revision 1.18.2.5
diff -u -b -r1.18.2.4 -r1.18.2.5
--- game/freegame.cpp   15 Dec 2007 20:32:34 -0000      1.18.2.4
+++ game/freegame.cpp   17 Dec 2007 11:27:41 -0000      1.18.2.5
@@ -42,7 +42,7 @@
 }
 
 
-int FreeGame::setRackRandom(int p, bool iCheck, set_rack_mode mode)
+int FreeGame::setRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
 {
     int res;
     do
@@ -79,17 +79,17 @@
 }
 
 
-void FreeGame::freegameAI(int n)
+void FreeGame::freegameAI(unsigned int p)
 {
-    ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
-    ASSERT(!m_players[n]->isHuman(), "AI requested for a human player");
+    ASSERT(p < getNPlayers(), "Wrong player number");
+    ASSERT(!m_players[p]->isHuman(), "AI requested for a human player");
 
-    AIPlayer *player = static_cast<AIPlayer*>(m_players[n]);
+    AIPlayer *player = static_cast<AIPlayer*>(m_players[p]);
 
     player->compute(m_dic, m_board, m_history.getSize());
     if (player->changesLetters())
     {
-        helperPass(player->getChangedLetters(), n);
+        helperPass(player->getChangedLetters(), p);
         endTurn();
     }
     else
@@ -110,7 +110,7 @@
     ASSERT(getNPlayers(), "Cannot start a game without any player");
 
     /* Set the initial racks of the players */
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         setRackRandom(i, false, RACK_NEW);
     }
@@ -170,7 +170,7 @@
     /* Add the points of the remaining tiles to the score of the current
      * player (i.e. the first player with an empty rack), and remove them
      * from the score of the players who still have tiles */
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         if (i != m_currPlayer)
         {
@@ -189,7 +189,7 @@
 }
 
 
-int FreeGame::pass(const wstring &iToChange, int n)
+int FreeGame::pass(const wstring &iToChange, unsigned int p)
 {
     if (m_finished)
         return 3;
@@ -212,16 +212,16 @@
         tilesVect.push_back(tile);
     }
 
-    int res = helperPass(tilesVect, n);
+    int res = helperPass(tilesVect, p);
     if (res == 0)
         endTurn();
     return res;
 }
 
 
-int FreeGame::helperPass(const vector<Tile> &iToChange, int n)
+int FreeGame::helperPass(const vector<Tile> &iToChange, unsigned int p)
 {
-    ASSERT(0 <= n && n < getNPlayers(), "Wrong player number");
+    ASSERT(p < getNPlayers(), "Wrong player number");
 
     // It is forbidden to change letters when the bag does not contain at
     // least 7 letters (this is explicitly stated in the ODS). But it is
@@ -233,7 +233,7 @@
         return 1;
     }
 
-    Player *player = m_players[n];
+    Player *player = m_players[p];
     PlayedRack pld = player->getCurrentRack();
     Rack rack;
     pld.getRack(rack);

Index: game/freegame.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.h,v
retrieving revision 1.11
retrieving revision 1.11.2.1
diff -u -b -r1.11 -r1.11.2.1
--- game/freegame.h     22 Jan 2006 12:23:53 -0000      1.11
+++ game/freegame.h     17 Dec 2007 11:27:41 -0000      1.11.2.1
@@ -49,19 +49,19 @@
      * Game handling
      *************************/
     virtual int start();
-    virtual int setRackRandom(int, bool, set_rack_mode);
+    virtual int setRackRandom(unsigned int, bool, set_rack_mode);
     virtual int play(const wstring &iCoord, const wstring &iWord);
     virtual int endTurn();
-    int pass(const wstring &iToChange, int n);
+    int pass(const wstring &iToChange, unsigned int p);
 
 private:
     // Private constructor and destructor to force using the GameFactory class
     FreeGame(const Dictionary &iDic);
     virtual ~FreeGame();
 
-    void freegameAI(int n);
+    void freegameAI(unsigned int p);
     void end();
-    int helperPass(const vector<Tile> &iToChange, int n);
+    int helperPass(const vector<Tile> &iToChange, unsigned int p);
 };
 
 #endif /* _FREEGAME_H_ */

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.31.2.8
retrieving revision 1.31.2.9
diff -u -b -r1.31.2.8 -r1.31.2.9
--- game/game.cpp       15 Dec 2007 20:32:34 -0000      1.31.2.8
+++ game/game.cpp       17 Dec 2007 11:27:41 -0000      1.31.2.9
@@ -49,22 +49,21 @@
 
 Game::~Game()
 {
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         delete m_players[i];
     }
 }
 
 
-const Player& Game::getPlayer(int iNum) const
+const Player& Game::getPlayer(unsigned int iNum) const
 {
-    ASSERT(0 <= iNum && iNum < (int)m_players.size(), "Wrong player number");
+    ASSERT(iNum < m_players.size(), "Wrong player number");
     return *(m_players[iNum]);
 }
 
 
-/* This function plays a round on the board */
-int Game::helperPlayRound(const Round &iRound)
+void Game::helperPlayRound(const Round &iRound)
 {
     /*
      * We remove tiles from the bag only when they are played
@@ -85,12 +84,12 @@
     // This is currently done by a succession of ugly hacks :-/
     if (m_variant == kJOKER)
     {
-        for (int i = 0; i < iRound.getWordLen(); i++)
+        for (unsigned int i = 0; i < iRound.getWordLen(); i++)
         {
             if (iRound.isPlayedFromRack(i) && iRound.isJoker(i))
             {
                 // Is the represented letter still available in the bag?
-                // FIXME: this way to get the represented letter sucks...
+                // XXX: this way to get the represented letter sucks...
                 Tile t(towupper(iRound.getTile(i).toChar()));
                 Bag bag(m_dic);
                 realBag(bag);
@@ -127,12 +126,15 @@
                     // rounds
                     const_cast<Round&>(iRound).setJoker(i, false);
                 }
+
+                // In a joker game we should have only 1 joker in the rack
+                break;
             }
         }
     }
 
     // Update the bag and the board
-    for (int i = 0; i < iRound.getWordLen(); i++)
+    for (unsigned int i = 0; i < iRound.getWordLen(); i++)
     {
         if (iRound.isPlayedFromRack(i))
         {
@@ -147,35 +149,26 @@
         }
     }
     m_board.addRound(m_dic, iRound);
-
-    return 0;
 }
 
 
-int Game::back(int n)
+int Game::back(unsigned int n)
 {
-    int i, j;
-    Player *player;
-
-    if (n < 0)
-    {
-        debug("Game::back negative argument\n");
-        n = -n;
-    }
     debug("Game::back %d\n",n);
-    for (i = 0; i < n; i++)
-    {
-        if (m_history.getSize() > 0)
+    // TODO: throw an exception
+    if (m_history.getSize() < n)
+        return 1;
+
+    for (unsigned int i = 0; i < n; i++)
         {
             prevPlayer();
-            player = m_players[m_currPlayer];
             const Round &lastround = m_history.getPreviousTurn().getRound();
             debug("Game::back last round %s\n",
                   convertToMb(lastround.toString()).c_str());
             /* Remove the word from the board, and put its letters back
              * into the bag */
             m_board.removeRound(m_dic, lastround);
-            for (j = 0; j < lastround.getWordLen(); j++)
+        for (unsigned int j = 0; j < lastround.getWordLen(); j++)
             {
                 if (lastround.isPlayedFromRack(j))
                 {
@@ -186,25 +179,17 @@
                 }
             }
             /* 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_history.removeLastTurn();
         }
-        else
-        {
-            return 1;
-        }
-    }
     return 0;
 }
 
-/**
- * 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.
- */
+
 void Game::realBag(Bag &ioBag) const
 {
     vector<Tile> tiles;
@@ -216,7 +201,7 @@
     if (getMode() == kFREEGAME)
     {
         /* In freegame mode, take the letters from all the racks */
-        for (int i = 0; i < getNPlayers(); i++)
+        for (unsigned int i = 0; i < getNPlayers(); i++)
         {
             getPlayer(i).getCurrentRack().getAllTiles(tiles);
             for (unsigned int j = 0; j < tiles.size(); j++)
@@ -238,9 +223,9 @@
 }
 
 
-int Game::helperSetRackRandom(int p, bool iCheck, set_rack_mode mode)
+int Game::helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
 {
-    ASSERT(0 <= p && p < getNPlayers(), "Wrong player number");
+    ASSERT(p < getNPlayers(), "Wrong player number");
 
     int nold, min;
 
@@ -392,16 +377,6 @@
 }
 
 
-/**
- * Check if the players rack can be obtained from the bag.
- * Since letters are removed from the bag only when the
- * round is played we need to check that ALL the racks 
- * are in the bag simultaneously.
- *
- * FIXME: since we do not check for all racks it works
- * for training and duplicate but it won't work for
- * freegames.
- */
 bool Game::rackInBag(const Rack &iRack, const Bag &iBag) const
 {
     const vector<Tile>& allTiles = m_dic.getAllTiles();
@@ -414,19 +389,16 @@
     return true;
 }
 
-/**
- * Set the rack of the player p manually.
- */
-int Game::helperSetRackManual(int p, bool iCheck, const wstring &iLetters)
+
+int Game::helperSetRackManual(unsigned int p, bool iCheck, const wstring 
&iLetters)
 {
+    ASSERT(p < getNPlayers(), "Wrong player number");
+
     if (!m_dic.validateLetters(iLetters, L"+"))
         return 3;
 
     PlayedRack pld;
-    if (pld.setManual(iLetters) > 0)
-    {
-        return 1; /* add new tests */
-    }
+    pld.setManual(iLetters);
 
     Rack rack;
     pld.getRack(rack);
@@ -457,10 +429,10 @@
  *********************************************************/
 
 
-int Game::getNHumanPlayers() const
+unsigned int Game::getNHumanPlayers() const
 {
-    int count = 0;
-    for (int i = 0; i < getNPlayers(); i++)
+    unsigned int count = 0;
+    for (unsigned int i = 0; i < getNPlayers(); i++)
         count += (getPlayer(i).isHuman() ? 1 : 0);
     return count;
 }
@@ -501,29 +473,14 @@
 }
 
 
-/*
- * This function checks whether it is legal to play the given word at the
- * given coordinates. If so, the function fills a Round object, also given as
- * a parameter.
- * Possible return values:
- *  0: correct word, the Round can be used by the caller
- *  1: no dictionary set
- *  2: invalid coordinates (unreadable or out of the board)
- *  3: word not present in the dictionary
- *  4: not enough letters in the rack to play the word
- *  5: word is part of a longer one
- *  6: word overwriting an existing letter
- *  7: invalid crosscheck, or word going out of the board
- *  8: word already present on the board (no new letter from the rack)
- *  9: isolated word (not connected to the rest)
- * 10: first word not horizontal
- * 11: first word not covering the H8 square
- */
 int Game::checkPlayedWord(const wstring &iCoord,
                           const wstring &iWord, Round &oRound)
 {
     ASSERT(getNPlayers() != 0, "Expected at least one player");
 
+    if (!m_dic.validateLetters(iWord))
+        return 12;
+
     int res;
     vector<Tile> tiles;
     Tile t;
@@ -571,7 +528,7 @@
     Player *player = m_players[m_currPlayer];
     player->getCurrentRack().getRack(rack);
 
-    for (int i = 0; i < oRound.getWordLen(); i++)
+    for (unsigned int i = 0; i < oRound.getWordLen(); i++)
     {
         if (oRound.isPlayedFromRack(i))
         {

Index: game/game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.29.2.5
retrieving revision 1.29.2.6
diff -u -b -r1.29.2.5 -r1.29.2.6
--- game/game.h 14 Dec 2007 18:12:32 -0000      1.29.2.5
+++ game/game.h 17 Dec 2007 11:27:41 -0000      1.29.2.6
@@ -54,6 +54,10 @@
     Game(const Dictionary &iDic);
     virtual ~Game();
 
+    /***************
+     * Game type
+     ***************/
+
     /// Game mode: each one of these modes is implemented in an inherited class
     enum GameMode
     {
@@ -79,20 +83,75 @@
     void setVariant(GameVariant iVariant)   { m_variant = iVariant; }
     GameVariant getVariant() const          { return m_variant; }
 
+    /***************
+     * Various getters
+     ***************/
+
     /**
-     * Dictionary associated with the game.
-     * The dictionary can be changed during a game without problem
+     * Get the dictionary associated with the game.
+     * You should never create a new dictionary object while a Game
+     * object still exists
      */
     const Dictionary & getDic() const   { return m_dic; }
 
+    /// Get the board
     const Board&  getBoard() const { return m_board; }
+    /// Get the bag
     const Bag&    getBag()   const { return m_bag; }
-    const Player& getPlayer(int iNum) const;
-    const Turn&   getTurn(int iNum) const;
+    /// Get the history of the game */
+    const History& getHistory() const { return m_history; }
+
+    /***************
+     * Methods to access players.
+     ***************/
+
+    const Player& getPlayer(unsigned int iNum) const;
     const Player& getCurrentPlayer() const { return getPlayer(currPlayer()); };
+    unsigned int getNPlayers() const { return m_players.size(); }
+    unsigned int getNHumanPlayers() const;
+    virtual void addHumanPlayer();
+    // TODO: Ability to specify which kind of AI player is wanted
+    virtual void addAIPlayer();
+    unsigned int currPlayer() const { return m_currPlayer; }
+
+    /***************
+     * Game handling
+     ***************/
+
+    /**
+     * Start the game, and make the AI players play.
+     * If the game only has AI players, it will play completely.
+     */
+    virtual int start() = 0;
 
     /**
-     * Eliot file formats
+     * Method used by human players to play the word iWord at coordinates
+     * iCoord, and end the turn (if possible)
+     */
+    virtual int play(const wstring &iCoord, const wstring &iWord) = 0;
+
+    /**
+     * End the current turn. This method is automatically called by start()
+     * and by play(), so should not be called directly
+     * FIXME: Do not make it public then!
+     */
+    virtual int endTurn() = 0;
+
+    /**
+     * Go back to turn iTurn.
+     * We must have: iTurn < getHistory().getSize()
+     * Possible return values:
+     *  0: everything went fine
+     *  1: iTurn is invalid
+     */
+    int back(unsigned int iTurn);
+
+    /***************
+     * Saved games handling
+     ***************/
+
+    /**
+     * Possible formats for the saved games
      */
     enum game_file_format
     {
@@ -101,16 +160,14 @@
     };
 
     /**
-     * Saved games handling.
-     *
      * load() returns the loaded game, or NULL if there was a problem
-     * load() might need some more work to be robust enough to
+     * load() does need some more work to be robust enough to
      * handle "hand written" files
      */
     static Game * load(FILE *fin, const Dictionary &iDic);
 
     /**
-     * Save a game to a File
+     * Save a game to a file
      * Standard format is used for training games so that it is compatible
      * with previous versions of Eliot.
      *
@@ -119,59 +176,18 @@
      */
     void save(ostream &out, game_file_format format = FILE_FORMAT_STANDARD) 
const;
 
-    /*************************
-     * Playing the game
-     * the int parameter should be 0 <= int < getNTurns
-     *************************/
-    int back(int);
+    /***************
+     * Setting the rack
+     ***************/
 
-    /*************************
-     * Set the rack for searching
-     *
-     * If 'check' is true, the rack will check that there are at least
-     * 2 vowels and 2 consonants before the round 15.
-     *
-     * The 'str' parameter has to contain
-     * 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '?'
-     *
-     * return value
-     *    0 : the rack has been set
-     *    1 : the bag does not contain enough tiles
-     *    2 : the rack check was set on and failed
-     *    3 : the rack cannot be completed (Game_*_setrackrandom only)
-     *************************/
     enum set_rack_mode {RACK_ALL, RACK_NEW, RACK_MANUAL};
-    int setRack(int player, set_rack_mode mode, bool check, const wstring& 
str);
 
-    /**
-     * Methods to access already played words.
-     * The int parameter should be 0 <= int < getNTurns()
-     */
-    const History& getHistory() const { return m_history; }
-
-    /**
-     * Methods to access players.
-     * The int parameter should be 0 <= int < getNPlayers()
-     */
-    int  getNPlayers() const    { return m_players.size(); }
-    int  getNHumanPlayers() const;
-    virtual void addHumanPlayer();
-    // TODO: Ability to specify which kind of AI player is wanted
-    virtual void addAIPlayer();
-    int  currPlayer() const     { return m_currPlayer; }
-
-    /**
-     * Game handling
-     */
-    virtual int start() = 0;
-    virtual int play(const wstring &iCoord, const wstring &iWord) = 0;
-    virtual int endTurn() = 0;
 
 protected:
     /// All the players, indexed by their ID
     vector<Player*> m_players;
     /// ID of the "current" player
-    int m_currPlayer;
+    unsigned int m_currPlayer;
 
 // TODO: check what should be private and what should be protected
 // private:
@@ -202,14 +218,71 @@
      * Helper functions
      *********************************************************/
 
-    int helperPlayRound(const Round &iRound);
-    int helperSetRackRandom(int p, bool iCheck, set_rack_mode mode);
-    int helperSetRackManual(int p, bool iCheck, const wstring &iLetters);
+    /** Play a round on the board */
+    void helperPlayRound(const Round &iRound);
+
+    /**
+     * Set the rack randomly for the player p
+     * Possible return values:
+     *  0: everything went fine
+     *  1: the game is over
+     *  2: the rack was checked and was not correct (try calling the
+     *     function again)
+     *  3: there is no chance to set the rack with the vowels/consonants
+     *     constraints
+     */
+    int helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode);
+
+    /**
+     * Set the rack for the player p with the given letters
+     * Possible return values:
+     *  0: everything went fine
+     *  1: the bag doesn't have the wanted letters
+     *  2: the rack was checked for vowels/consonants and was not correct
+     */
+    int helperSetRackManual(unsigned int p, bool iCheck, const wstring 
&iLetters);
 
     void prevPlayer();
     void nextPlayer();
+
+    /**
+     * Check if the players rack can be obtained from the bag.
+     * Since letters are removed from the bag only when the
+     * round is played we need to check that ALL the racks 
+     * are in the bag simultaneously.
+     *
+     * FIXME: since we do not check for all racks it works
+     * for training and duplicate but it won't work for
+     * freegames.
+     */
     bool rackInBag(const Rack &iRack, const Bag &iBag) const;
+
+    /**
+     * 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.
+     */
     void realBag(Bag &iBag) const;
+
+    /**
+     * This function checks whether it is legal to play the given word at the
+     * given coordinates. If so, the function fills a Round object, also given
+     * as a parameter.
+     * Possible return values:
+     *  0: correct word, the Round can be used by the caller
+     *  1: no dictionary set
+     *  2: invalid coordinates (unreadable or out of the board)
+     *  3: word not present in the dictionary
+     *  4: not enough letters in the rack to play the word
+     *  5: word is part of a longer one
+     *  6: word overwriting an existing letter
+     *  7: invalid crosscheck, or word going out of the board
+     *  8: word already present on the board (no new letter from the rack)
+     *  9: isolated word (not connected to the rest)
+     * 10: first word not horizontal
+     * 11: first word not covering the H8 square
+     * 12: one letter of the word is invalid in the current dictionary
+     */
     int  checkPlayedWord(const wstring &iCoord,
                          const wstring &iWord, Round &oRound);
 
@@ -235,6 +308,8 @@
      */
     void gameSaveFormat_15(ostream &out) const;
 
+private:
+
 };
 
 #endif /* _GAME_H_ */

Index: game/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_io.cpp,v
retrieving revision 1.4.2.3
retrieving revision 1.4.2.4
diff -u -b -r1.4.2.3 -r1.4.2.4
--- game/game_io.cpp    6 Dec 2007 15:06:06 -0000       1.4.2.3
+++ game/game_io.cpp    17 Dec 2007 11:27:41 -0000      1.4.2.4
@@ -25,6 +25,7 @@
  *  \date   2002 - 2005
  */
 
+#include "dic.h"
 #include "pldrack.h"
 #include "round.h"
 #include "turn.h"
@@ -320,7 +321,7 @@
         char tmpWord[20];
         char ref[4];
         int pts;
-        int player;
+        unsigned int player;
         char bonus = 0;
         int res = sscanf(buff, "   %2d | %8s | %s | %3s | %3d | %1d | %c",
                          &num, rack, tmpWord, ref, &pts, &player, &bonus);
@@ -343,7 +344,7 @@
             debug("   Game::load15 line -%s- points < 0  ?\n",buff);
             continue;
         }
-        if (player < 0 || player > pGame->getNPlayers())
+        if (player > pGame->getNPlayers())
         {
             debug("   Game::load15 line -%s- too much player 
(%d>%d)",buff,player,pGame->getNPlayers());
             continue;
@@ -356,10 +357,11 @@
 
         // Build a rack for the correct player
         PlayedRack pldrack;
-        if ((res = pldrack.setManual(convertToWc(rack))) > 0)
+        if (!iDic.validateLetters(convertToWc(rack)))
         {
-            debug("   Game::load15 set rack manual returned with error 
%d\n",res);
+            debug("   Game::load15 rack invalid for the current dictionary\n");
         }
+        pldrack.setManual(convertToWc(rack));
         debug("    history rack %s\n", 
convertToMb(pldrack.toString()).c_str());
 
         // Build a round
@@ -453,7 +455,7 @@
     {
         // We don't really know whose turn it is, but at least we know that
         // the game was saved while a human was to play.
-        for (int i = 0; i < pGame->getNPlayers(); i++)
+        for (unsigned int i = 0; i < pGame->getNPlayers(); i++)
         {
             if (pGame->m_players[i]->isHuman())
             {
@@ -491,7 +493,7 @@
     const string decal = "   ";
     out << IDENT_STRING << endl << endl;
 
-    for (int i = 0; i < m_history.getSize(); i++)
+    for (unsigned int i = 0; i < m_history.getSize(); i++)
     {
         const Turn& turn = m_history.getTurn(i);
         wstring rack = turn.getPlayedRack().toString(PlayedRack::RACK_EXTRA);
@@ -525,7 +527,7 @@
     // Game type
     out << "Game type: " << getModeAsString() << endl;
     // Player list
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         out << "Player " << i << ": ";
         if (m_players[i]->isHuman())
@@ -541,7 +543,7 @@
     out << decal << "===|==========|=================|=====|=====|===|======" 
<< endl;
 
     // Print the game itself
-    for (int i = 0; i < m_history.getSize(); i++)
+    for (unsigned int i = 0; i < m_history.getSize(); i++)
     {
         const Turn& turn = m_history.getTurn(i);
         wstring rack = turn.getPlayedRack().toString(PlayedRack::RACK_EXTRA);
@@ -575,7 +577,7 @@
 
     // Print current rack for all the players
     out << endl;
-    for (int i = 0; i < getNPlayers(); i++)
+    for (unsigned int i = 0; i < getNPlayers(); i++)
     {
         wstring rack = m_players[i]->getCurrentRack().toString();
         out << "Rack " << i << ": " << convertToMb(rack) << endl;

Index: game/history.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/history.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/history.cpp    27 Nov 2007 18:01:06 -0000      1.10.2.2
+++ game/history.cpp    17 Dec 2007 11:27:41 -0000      1.10.2.3
@@ -41,7 +41,7 @@
 
 History::History()
 {
-    Turn* t = new Turn ();
+    Turn* t = new Turn();
     m_history.clear();
     m_history.push_back(t);
 }
@@ -56,8 +56,9 @@
 }
 
 
-int History::getSize() const
+unsigned int History::getSize() const
 {
+    ASSERT(!m_history.empty(), "Invalid history size");
     return m_history.size() - 1;
 }
 
@@ -88,17 +89,10 @@
     return *(m_history[n]);
 }
 
-/*
- * This function increments the number of racks, and fills the new rack
- * with the unplayed tiles from the previous one.
- * 03 sept 2000 : We have to sort the tiles according to the new rules
- */
-void History::playRound(int player, int turn, const Round& round)
-{
-    Rack rack;
-    Turn * current_turn;
 
-    current_turn = m_history.back();
+void History::playRound(unsigned int player, unsigned int turn, const Round& 
round)
+{
+    Turn * current_turn = m_history.back();
 
     /* set the number and the round */
     current_turn->setNum(turn);
@@ -106,10 +100,11 @@
     current_turn->setRound(round);
 
     /* get what was the rack for the current turn */
+    Rack rack;
     current_turn->getPlayedRack().getRack(rack);
 
     /* remove the played tiles from the rack */
-    for (int i = 0; i < round.getWordLen(); i++)
+    for (unsigned int i = 0; i < round.getWordLen(); i++)
     {
         if (round.isPlayedFromRack(i))
         {
@@ -142,7 +137,7 @@
     }
 
     // Now we have the previous played round in back()
-    Turn* t = m_history.back();
+    Turn *t = m_history.back();
     t->setNum(0);
     t->setPlayer(0);
     t->setRound(Round());

Index: game/history.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/history.h,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -u -b -r1.11.2.1 -r1.11.2.2
--- game/history.h      13 Dec 2007 12:11:07 -0000      1.11.2.1
+++ game/history.h      17 Dec 2007 11:27:41 -0000      1.11.2.2
@@ -41,15 +41,12 @@
  * History stores all the turns that have been played
  * This class is used many times in the game
  *  - one for the complete game
- *  - one for each of the players
+ *  - one for each player
  *
- * A History is never void (getSize() can be used as the is the current turn
- * number for the complete game history).
- *
- * History starts at zero.
- *
- * The top of the history is an empty
- * Turn until it has been filled and game is up to a new round.
+ * The top of the history is an empty Turn until it has been filled
+ * and the game is up to a new turn. So a History object is never empty.
+ * However, the getSize() method only returns the number of complete
+ * turns, and can therefore return 0.
  *
  * getCurrentRack() can/should be used to store the current played rack.
  * setCurrentRack must be called whenever the current played rack is
@@ -58,15 +55,14 @@
  * History owns the turns that it stores. Do not delete a turn referenced
  * by History
  */
-
 class History
 {
  public:
     History();
     ~History();
 
-    /// get the size of the history
-    int               getSize() const;
+    /// Get the size of the history (without the current incomplete turn)
+    unsigned int getSize() const;
 
     /// Get the (possibly incomplete) rack
     const PlayedRack& getCurrentRack() const;
@@ -74,15 +70,18 @@
     /// Set the current rack
     void              setCurrentRack(const PlayedRack &iPld);
 
-    /// Get the previous turn
+    /// Get the previous (complete) turn
     const Turn&       getPreviousTurn() const;
 
-    /// Get turn 'n'
+    /// Get turn 'n' (starting at 0)
     const Turn&       getTurn(unsigned int) const;
 
-    /// Update the "history" with the given round and complete the turn.
-    /// A new turn is created with the remaining letters in the rack
-    void playRound(int player, int turn, const Round& round);
+    /**
+     * Update the history with the given round and complete the turn.
+     * A new turn is created with the unplayed letters in the rack
+     * 03 sept 2000: We have to sort the tiles according to the new rules
+     */
+    void playRound(unsigned int player, unsigned int turn, const Round& round);
 
     /// Remove last turn
     void removeLastTurn();

Index: game/player.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player.cpp,v
retrieving revision 1.14.2.1
retrieving revision 1.14.2.2
diff -u -b -r1.14.2.1 -r1.14.2.2
--- game/player.cpp     13 Dec 2007 12:11:07 -0000      1.14.2.1
+++ game/player.cpp     17 Dec 2007 11:27:41 -0000      1.14.2.2
@@ -31,7 +31,7 @@
 #include "debug.h"
 
 
-Player::Player(int iId)
+Player::Player(unsigned int iId)
     : m_id(iId), m_score(0)
 {
 }
@@ -61,9 +61,9 @@
 }
 
 
-void Player::endTurn(const Round &iRound, int iTurn)
+void Player::endTurn(const Round &iRound, unsigned int iTurn)
 {
-    m_history.playRound(m_id,iTurn,iRound);
+    m_history.playRound(m_id, iTurn, iRound);
 }
 
 void Player::removeLastTurn()

Index: game/player.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player.h,v
retrieving revision 1.18.2.1
retrieving revision 1.18.2.2
diff -u -b -r1.18.2.1 -r1.18.2.2
--- game/player.h       13 Dec 2007 12:11:07 -0000      1.18.2.1
+++ game/player.h       17 Dec 2007 11:27:41 -0000      1.18.2.2
@@ -35,7 +35,7 @@
 class Player
 {
 public:
-    Player(int iId);
+    explicit Player(unsigned int iId);
     virtual ~Player() {}
 
     // Pseudo RTTI
@@ -67,13 +67,13 @@
 
     // Update the player "history", with the given round.
     // A new rack is created with the remaining letters
-    void endTurn(const Round &iRound, int iTurn);
+    void endTurn(const Round &iRound, unsigned int iTurn);
 
     wstring toString() const;
 
 private:
     /// ID of the player
-    int m_id;
+    unsigned int m_id;
 
     /// Score of the player
     int m_score;

Index: game/pldrack.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.cpp,v
retrieving revision 1.9.2.2
retrieving revision 1.9.2.3
diff -u -b -r1.9.2.2 -r1.9.2.3
--- game/pldrack.cpp    14 Dec 2007 18:12:33 -0000      1.9.2.2
+++ game/pldrack.cpp    17 Dec 2007 11:27:42 -0000      1.9.2.3
@@ -131,40 +131,27 @@
 }
 
 
-int PlayedRack::setManual(const wstring& iLetters)
+void PlayedRack::setManual(const wstring& iLetters)
 {
     unsigned int i;
     reset();
 
+    // An empty rack is OK
     if (iLetters.empty())
-    {
-        return 0; /* empty is ok */
-    }
+        return;
 
     for (i = 0; i < iLetters.size() && iLetters[i] != L'+'; i++)
     {
-        Tile tile(iLetters[i]);
-        if (tile.isEmpty())
-        {
-            return 1; /* */
-        }
-        addOld(tile);
+        addOld(Tile(iLetters[i]));
     }
 
     if (i < iLetters.size() && iLetters[i] == L'+')
     {
         for (i++; i < iLetters.size(); i++)
         {
-            Tile tile(iLetters[i]);
-            if (tile.isEmpty())
-            {
-                return 1; /* */
-            }
-            addNew(tile);
+            addNew(Tile(iLetters[i]));
         }
     }
-
-    return 0;
 }
 
 

Index: game/pldrack.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.h,v
retrieving revision 1.12.2.2
retrieving revision 1.12.2.3
diff -u -b -r1.12.2.2 -r1.12.2.3
--- game/pldrack.h      14 Dec 2007 18:12:33 -0000      1.12.2.2
+++ game/pldrack.h      17 Dec 2007 11:27:42 -0000      1.12.2.3
@@ -57,7 +57,7 @@
 
     void setOld(const Rack &iRack);
     void setNew(const Rack &iRack);
-    int  setManual(const wstring& iLetters);
+    void setManual(const wstring& iLetters);
 
     int nTiles() const  { return nNew() + nOld(); }
     int nNew() const    { return m_newTiles.size(); }

Index: game/results.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/results.cpp,v
retrieving revision 1.10.2.1
retrieving revision 1.10.2.2
diff -u -b -r1.10.2.1 -r1.10.2.2
--- game/results.cpp    13 Dec 2007 12:11:07 -0000      1.10.2.1
+++ game/results.cpp    17 Dec 2007 11:27:42 -0000      1.10.2.2
@@ -54,7 +54,7 @@
 
 
 void Results::search(const Dictionary &iDic, Board &iBoard,
-                     const Rack &iRack, int iTurn)
+                     const Rack &iRack, unsigned int iTurn)
 {
     clear();
 

Index: game/results.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/results.h,v
retrieving revision 1.8.2.2
retrieving revision 1.8.2.3
diff -u -b -r1.8.2.2 -r1.8.2.3
--- game/results.h      13 Dec 2007 12:11:07 -0000      1.8.2.2
+++ game/results.h      17 Dec 2007 11:27:42 -0000      1.8.2.3
@@ -47,15 +47,13 @@
 class Results
 {
 public:
-    Results() {}
-
     int size() const    { return m_rounds.size(); }
     void clear()        { m_rounds.clear(); }
     const Round & get(int) const;
 
     // Perform a search on the board
     void search(const Dictionary &iDic, Board &iBoard,
-                const Rack &iRack, int iTurn);
+                const Rack &iRack, unsigned int iTurn);
 
     // FIXME: This method is used to fill the container with the rounds,
     // but it should not be part of the public interface

Index: game/round.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/round.cpp,v
retrieving revision 1.10.2.3
retrieving revision 1.10.2.4
diff -u -b -r1.10.2.3 -r1.10.2.4
--- game/round.cpp      13 Dec 2007 12:11:07 -0000      1.10.2.3
+++ game/round.cpp      17 Dec 2007 11:27:42 -0000      1.10.2.4
@@ -58,21 +58,21 @@
 }
 
 
-void Round::setFromRack(int iIndex)
+void Round::setFromRack(unsigned int iIndex)
 {
     m_tileOrigin[iIndex] &= ~FROMBOARD;
     m_tileOrigin[iIndex] |= FROMRACK;
 }
 
 
-void Round::setFromBoard(int iIndex)
+void Round::setFromBoard(unsigned int iIndex)
 {
     m_tileOrigin[iIndex] &= ~FROMRACK;
     m_tileOrigin[iIndex] |= FROMBOARD;
 }
 
 
-void Round::setJoker(int iIndex, bool value)
+void Round::setJoker(unsigned int iIndex, bool value)
 {
     if (value)
         m_tileOrigin[iIndex] |= JOKER;
@@ -81,25 +81,19 @@
 }
 
 
-bool Round::isJoker(int iIndex) const
+bool Round::isJoker(unsigned int iIndex) const
 {
      return m_tileOrigin[iIndex] & JOKER;
 }
 
 
-const Tile& Round::getTile(int iIndex) const
+const Tile& Round::getTile(unsigned int iIndex) const
 {
      return m_word[iIndex];
 }
 
 
-int Round::getWordLen() const
-{
-     return m_word.size();
-}
-
-
-bool Round::isPlayedFromRack(int iIndex) const
+bool Round::isPlayedFromRack(unsigned int iIndex) const
 {
      return m_tileOrigin[iIndex] & FROMRACK;
 }
@@ -144,7 +138,7 @@
     wchar_t c;
     wstring s;
 
-    for (int i = 0; i < getWordLen(); i++)
+    for (unsigned int i = 0; i < getWordLen(); i++)
     {
         c = getTile(i).toChar();
         if (isJoker(i))

Index: game/round.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/round.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/round.h        13 Dec 2007 12:11:07 -0000      1.12.2.1
+++ game/round.h        17 Dec 2007 11:27:42 -0000      1.12.2.2
@@ -57,21 +57,21 @@
      *************************/
     void setPoints(int iPoints)    { m_points = iPoints; }
     void setBonus(bool iBonus)     { m_bonus = iBonus; }
-    void setTile(int iIndex, const Tile &iTile) { m_word[iIndex] = iTile; }
+    void setTile(unsigned int iIndex, const Tile &iTile) { m_word[iIndex] = 
iTile; }
     void setWord(const vector<Tile> &iTiles);
-    void setFromRack(int iIndex);
-    void setFromBoard(int iIndex);
-    void setJoker(int iIndex, bool value = true);
+    void setFromRack(unsigned int iIndex);
+    void setFromBoard(unsigned int iIndex);
+    void setJoker(unsigned int iIndex, bool value = true);
 
     /*************************
      * General getters
      *************************/
-    bool isJoker         (int iIndex) const;
-    bool isPlayedFromRack(int iIndex) const;
-    const Tile& getTile  (int iIndex) const;
+    bool isJoker         (unsigned int iIndex) const;
+    bool isPlayedFromRack(unsigned int iIndex) const;
+    const Tile& getTile  (unsigned int iIndex) const;
 
     wstring getWord() const;
-    int getWordLen()  const;
+    unsigned int getWordLen() const { return m_word.size(); }
     int getPoints()   const       { return m_points; }
     int getBonus()    const       { return m_bonus; }
 

Index: game/training.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.cpp,v
retrieving revision 1.17.2.2
retrieving revision 1.17.2.3
diff -u -b -r1.17.2.2 -r1.17.2.3
--- game/training.cpp   15 Dec 2007 20:32:34 -0000      1.17.2.2
+++ game/training.cpp   17 Dec 2007 11:27:42 -0000      1.17.2.3
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include <algorithm>
+
 #include "dic.h"
 #include "tile.h"
 #include "rack.h"
@@ -30,7 +32,8 @@
 #include "debug.h"
 
 
-Training::Training(const Dictionary &iDic): Game(iDic)
+Training::Training(const Dictionary &iDic)
+    : Game(iDic)
 {
 }
 
@@ -46,7 +49,7 @@
 
     int res;
     int try_number = 0;
-    int p = m_currPlayer;
+    unsigned int p = m_currPlayer;
     m_results.clear();
     do
     {
@@ -63,23 +66,23 @@
 int Training::setRackManual(bool iCheck, const wstring &iLetters)
 {
     int res;
-    int p = m_currPlayer;
+    unsigned int p = m_currPlayer;
     wstring::iterator it;
-    wstring uLetters; // uppercase letters
-    // letters can be lowercase or uppercase as they are
+    wstring upperLetters = iLetters;
+    // Letters can be lowercase or uppercase as they are
     // coming from user input. We do not consider a lowercase
     // letter to be a joker which has been assigned to a letter.
-    m_results.clear();
-    uLetters = iLetters;
-    for (it = uLetters.begin(); it != uLetters.end(); it ++)
-    {
-        *it = towupper(*it);
-    }
-    res = helperSetRackManual(p, iCheck, uLetters);
+    // As a result, we simply make all the letters uppercase
+    upperLetters = iLetters;
+    std::transform(upperLetters.begin(), upperLetters.end(),
+                   upperLetters.begin(), towupper);
+    res = helperSetRackManual(p, iCheck, upperLetters);
     // 0: ok
     // 1: not enough tiles
     // 2: check failed (number of vowels before round 15)
     // 3: letters not in the dictionary
+    if (res == 0)
+        m_results.clear();
     return res;
 }
 
@@ -126,10 +129,7 @@
     m_players[m_currPlayer]->endTurn(round, m_history.getSize());
 
     /* Everything is OK, we can play the word */
-    if (helperPlayRound(round))
-    {
-        debug("play: error during play\n");
-    }
+    helperPlayRound(round);
 
     /* Next turn */
     endTurn();
@@ -178,16 +178,14 @@
     player->addPoints(round.getPoints());
     player->endTurn(round, m_history.getSize());
 
-    int res = helperPlayRound(round);
-
-    if (res == 0)
+    helperPlayRound(round);
         m_results.clear();
 
     /* Next turn */
     // XXX: Should it be done by the interface instead?
     endTurn();
 
-    return res;
+    return 0;
 }
 
 

Index: game/turn.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn.cpp,v
retrieving revision 1.11.2.1
retrieving revision 1.11.2.2
diff -u -b -r1.11.2.1 -r1.11.2.2
--- game/turn.cpp       13 Dec 2007 12:11:08 -0000      1.11.2.1
+++ game/turn.cpp       17 Dec 2007 11:27:42 -0000      1.11.2.2
@@ -35,21 +35,13 @@
 {
 }
 
-Turn::Turn(int iNum, int iPlayerId,
+
+Turn::Turn(unsigned int iNum, unsigned int iPlayerId,
            const PlayedRack& iPldRack, const Round& iRound)
     : m_num(iNum), m_playerId(iPlayerId), m_pldrack(iPldRack), m_round(iRound)
 {
 }
 
-#if 0
-void Turn::operator=(const Turn &iOther)
-{
-    m_num      = iOther.m_num;
-    m_playerId = iOther.m_playerId;
-    m_pldrack  = iOther.m_pldrack;
-    m_round    = iOther.m_round;
-}
-#endif
 
 wstring Turn::toString(bool iShowExtraSigns) const
 {

Index: game/turn.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn.h,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/turn.h 13 Dec 2007 12:11:08 -0000      1.9.2.1
+++ game/turn.h 17 Dec 2007 11:27:42 -0000      1.9.2.2
@@ -27,31 +27,41 @@
 #ifndef _TURN_H
 #define _TURN_H
 
+#include <string>
+
+using std::wstring;
+
+
+/**
+ * A Turn is the information about one 'move' done by a player.
+ * It consists of the player who played, the rack, and the played round.
+ * A turn also has an id (XXX: currently never read)
+ *
+ * This class has no logic, it is merely there to aggregate corresponding
+ * data.
+ */
 class Turn
 {
 public:
     Turn();
-    Turn(int iNum, int iPlayerId,
+    Turn(unsigned int iNum, unsigned int iPlayerId,
          const PlayedRack& iPldRack, const Round& iRound);
 
-    void setNum(int iNum)                          { m_num = iNum; }
-    void setPlayer(int iPlayerId)                  { m_playerId = iPlayerId; }
+    void setNum(unsigned int iNum)                 { m_num = iNum; }
+    void setPlayer(unsigned int iPlayerId)         { m_playerId = iPlayerId; }
     void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
     void setRound(const Round& iRound)             { m_round = iRound; }
 
-    int               getNum()        const { return m_num; }
-    int               getPlayer()     const { return m_playerId; }
+    unsigned int      getNum()        const { return m_num; }
+    unsigned int      getPlayer()     const { return m_playerId; }
     const PlayedRack& getPlayedRack() const { return m_pldrack; }
     const Round&      getRound()      const { return m_round; }
 
-#if 0
-    void operator=(const Turn &iOther);
-#endif
     wstring toString(bool iShowExtraSigns = false) const;
 
 private:
-    int        m_num;
-    int        m_playerId;
+    unsigned int m_num;
+    unsigned int m_playerId;
     PlayedRack m_pldrack;
     Round      m_round;
 

Index: utils/game_io.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/game_io.cpp,v
retrieving revision 1.9.2.4
retrieving revision 1.9.2.5
diff -u -b -r1.9.2.4 -r1.9.2.5
--- utils/game_io.cpp   4 Dec 2007 11:10:00 -0000       1.9.2.4
+++ utils/game_io.cpp   17 Dec 2007 11:27:42 -0000      1.9.2.5
@@ -205,7 +205,7 @@
 
 void GameIO::printAllRacks(ostream &out, const Game &iGame)
 {
-    for (int j = 0; j < iGame.getNPlayers(); j++)
+    for (unsigned int j = 0; j < iGame.getNPlayers(); j++)
     {
         out << "Joueur " << j << ": ";
         out << 
convertToMb(iGame.getPlayer(j).getCurrentRack().toString(PlayedRack::RACK_SIMPLE))
 << endl;
@@ -247,7 +247,7 @@
 
 void GameIO::printAllPoints(ostream &out, const Game &iGame)
 {
-    for (int i = 0; i < iGame.getNPlayers(); i++)
+    for (unsigned int i = 0; i < iGame.getNPlayers(); i++)
     {
         out << "Joueur " << i << ": "
             << setw(4) << iGame.getPlayer(i).getPoints() << endl;

Index: utils/ncurses.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/utils/ncurses.cpp,v
retrieving revision 1.22.2.9
retrieving revision 1.22.2.10
diff -u -b -r1.22.2.9 -r1.22.2.10
--- utils/ncurses.cpp   16 Dec 2007 18:20:55 -0000      1.22.2.9
+++ utils/ncurses.cpp   17 Dec 2007 11:27:42 -0000      1.22.2.10
@@ -268,7 +268,7 @@
 {
     Box box(win, y, x, m_game->getNPlayers() + 2, 25);
     box.draw(_("Scores"));
-    for (int i = 0; i < m_game->getNPlayers(); i++)
+    for (unsigned int i = 0; i < m_game->getNPlayers(); i++)
     {
         if (m_game->getMode() != Game::kTRAINING && i == m_game->currPlayer())
             attron(A_BOLD);
@@ -279,11 +279,11 @@
     }
 
     // Distance between the 2 boxes
-    int yOff = m_game->getNPlayers() + 3;
+    unsigned int yOff = m_game->getNPlayers() + 3;
 
     Box box2(win, y + yOff, x, m_game->getNPlayers() + 2, 25);
     box2.draw(_("Racks"));
-    for (int i = 0; i < m_game->getNPlayers(); i++)
+    for (unsigned int i = 0; i < m_game->getNPlayers(); i++)
     {
         if (m_game->getMode() != Game::kTRAINING && i == m_game->currPlayer())
             attron(A_BOLD);
@@ -342,7 +342,7 @@
     ioBox.clearData();
 
     ioBox.draw(_("History of the game"));
-    ioBox.setDataSize(m_game->getHistory().getSize());
+    ioBox.setDataSize((int)m_game->getHistory().getSize());
     int x = ioBox.getLeft();
     int y = ioBox.getTop();
 
@@ -354,7 +354,7 @@
 
     int i;
     for (i = ioBox.getFirstLine();
-         i < m_game->getHistory().getSize() && i < ioBox.getLastLine(); i++)
+         i < (int)m_game->getHistory().getSize() && i < ioBox.getLastLine(); 
i++)
     {
         const Turn& t = m_game->getHistory().getTurn(i);
         const Round& r = t.getRound();
@@ -556,14 +556,15 @@
         {
             snprintf(s, 100, _("Cannot open file %ls for writing"),
                      filename.c_str());
+            drawStatus(win, s);
         }
         else
         {
-            m_game->save(fout);
+            m_game->save(fout, Game::FILE_FORMAT_ADVANCED);
             fout.close();
-            snprintf(s, 100, _("Game saved in %ls"), filename.c_str());
+            snprintf(s, 100, _("Game saved in '%ls'"), filename.c_str());
+            drawStatus(win, s, false);
         }
-        drawStatus(win, s);
     }
     box.clear();
 }
@@ -583,7 +584,7 @@
         FILE *fin;
         if ((fin = fopen(convertToMb(filename).c_str(), "r")) == NULL)
         {
-            snprintf(s, 100, _("Cannot open file %ls for reading"),
+            snprintf(s, 100, _("Cannot open file '%ls' for reading"),
                      filename.c_str());
         }
         else
@@ -592,16 +593,17 @@
             if (loaded == NULL)
             {
                 snprintf(s, 100, _("Invalid saved game"));
+                drawStatus(win, s);
             }
             else
             {
                 snprintf(s, 100, _("Game loaded"));
                 GameFactory::Instance()->releaseGame(*m_game);
                 m_game = loaded;
+                drawStatus(win, s, false);
             }
             fclose(fin);
         }
-        drawStatus(win, s);
     }
     box.clear();
 }

Index: wxwin/mainframe.cc
===================================================================
RCS file: /cvsroot/eliot/eliot/wxwin/mainframe.cc,v
retrieving revision 1.21.2.7
retrieving revision 1.21.2.8
diff -u -b -r1.21.2.7 -r1.21.2.8
--- wxwin/mainframe.cc  15 Dec 2007 20:32:34 -0000      1.21.2.7
+++ wxwin/mainframe.cc  17 Dec 2007 11:27:43 -0000      1.21.2.8
@@ -436,12 +436,7 @@
         return;
     }
 
-    std::wstring r;
-
-    if (m_game->getHistory().getSize() >= 0)
-    {
-        r = m_game->getCurrentPlayer().getCurrentRack().toString();
-    }
+    std::wstring r = m_game->getCurrentPlayer().getCurrentRack().toString();
 
     rack->SetValue(wxU(r.c_str()));
     // update gfxboard and all frames




reply via email to

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