eliot-dev
[Top][All Lists]
Advanced

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

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


From: eliot-dev
Subject: [Eliot-dev] eliot/game game.h game.cpp
Date: Mon, 26 Dec 2005 22:58:58 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Branch:         
Changes by:     Antoine Fraboulet <address@hidden>      05/12/26 22:58:58

Modified files:
        game           : game.h game.cpp 

Log message:
        - use History class
        - back is still buggy

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/game.h.diff?tr1=1.23&tr2=1.24&r1=text&r2=text
http://cvs.savannah.gnu.org/viewcvs/eliot/eliot/game/game.cpp.diff?tr1=1.23&tr2=1.24&r1=text&r2=text

Patches:
Index: eliot/game/game.cpp
diff -u eliot/game/game.cpp:1.23 eliot/game/game.cpp:1.24
--- eliot/game/game.cpp:1.23    Sun Nov  6 17:13:45 2005
+++ eliot/game/game.cpp Mon Dec 26 22:58:58 2005
@@ -49,10 +49,6 @@
 
 Game::~Game()
 {
-    for (unsigned int i = 0; i < m_history.size(); i++)
-    {
-        delete m_history[i];
-    }
     for (int i = 0; i < getNPlayers(); i++)
     {
         delete m_players[i];
@@ -67,13 +63,6 @@
 }
 
 
-const Turn& Game::getTurn(int iNum) const
-{
-    ASSERT(0 <= iNum && iNum < (int)m_history.size(), "Wrong turn number");
-    return *(m_history[iNum]);
-}
-
-
 Game * Game::load(FILE *fin, const Dictionary &iDic)
 {
     char buff[4096];
@@ -312,15 +301,16 @@
     out << decal << "===|==========|=================|=====|=====|===|======" 
<< endl;
 
     // Print the game itself
-    for (int i = 0; i < getNTurns(); i++)
+    for (int i = 0; i < m_history.getSize(); i++)
     {
-        string word = getPlayedWord(i);
-        string coord = getPlayedCoords(i);
+        const Turn& t = m_history.getTurn(i);
+        string word = t.getRound().getWord();
+        string coord = t.getRound().getCoord().toString();
         sprintf(line, "%2d | %8s | %s%s | %3s | %3d | %1d | %c",
-                i + 1, getPlayedRack(i).c_str(), word.c_str(),
+                i + 1, t.getPlayedRack().toString().c_str(), word.c_str(),
                 string(15 - word.size(), ' ').c_str(),
-                coord.c_str(), getPlayedPoints(i),
-                getPlayedPlayer(i), getPlayedBonus(i) ? '*' : ' ');
+                coord.c_str(), t.getRound().getPoints(),
+                t.getPlayer(), t.getRound().getBonus() ? '*' : ' ');
 
         out << decal << line << endl;
     }
@@ -347,9 +337,8 @@
      */
 
     // History of the game
-    m_history.push_back(new Turn(m_history.size(), m_currPlayer,
-                                 getPlayer(m_currPlayer).getLastRack(),
-                                 iRound));
+  m_history.setCurrentRack(getCurrentPlayer().getLastRack());
+  m_history.playRound(m_currPlayer, m_history.getSize(),  iRound);
 
     m_points += iRound.getPoints();
 
@@ -430,11 +419,11 @@
 
     for (i = 0; i < n; i++)
     {
-        if (m_history.size())
+        if (m_history.getSize())
         {
             prevPlayer();
             player = m_players[m_currPlayer];
-            const Round &lastround = m_history.back()->getRound();
+            const Round &lastround = m_history.getPreviousTurn().getRound();
 
             /* Remove the points of this round */
             player->addPoints(- lastround.getPoints());
@@ -453,7 +442,7 @@
                 }
             }
             delete &lastround;
-            m_history.pop_back();
+            m_history.removeLastTurn();
         }
         else
         {
@@ -570,7 +559,7 @@
         }
         // 2 vowels and 2 consonants are needed up to the 15th turn
         if (bag.nVowels() > 1 && bag.nConsonants() > 1
-            && getNTurns() < 15)
+            && m_history.getSize() < 15)
             min = 2;
         else
             min = 1;
@@ -700,7 +689,7 @@
     if (iCheck)
     {
         if (m_bag.nVowels() > 1 && m_bag.nConsonants() > 1
-            && getNTurns() < 15)
+            && m_history.getSize() < 15)
             min = 2;
         else
             min = 1;
@@ -716,53 +705,6 @@
 /*********************************************************
  *********************************************************/
 
-string Game::getPlayedRack(int num) const
-{
-    return getTurn(num).getPlayedRack().toString();
-}
-
-
-string Game::getPlayedWord(int num) const
-{
-    char c;
-    string s;
-    const Round &r = getTurn(num).getRound();
-    for (int i = 0; i < r.getWordLen(); i++)
-    {
-        c = r.getTile(i).toChar();
-        if (r.isJoker(i))
-            c = tolower(c);
-        s += c;
-    }
-    return s;
-}
-
-
-string Game::getPlayedCoords(int num) const
-{
-    return getTurn(num).getRound().getCoord().toString();
-}
-
-
-int Game::getPlayedPoints(int num) const
-{
-    return getTurn(num).getRound().getPoints();
-}
-
-
-int Game::getPlayedBonus(int num) const
-{
-    return getTurn(num).getRound().getBonus();
-}
-
-
-int Game::getPlayedPlayer(int num) const
-{
-    return getTurn(num).getPlayer();
-}
-
-/*********************************************************
- *********************************************************/
 
 string Game::getPlayerRack(int num, bool iShowExtraSigns) const
 {
@@ -868,7 +810,7 @@
 
     /* Check the word position, compute its points,
      * and specify the origin of each letter (board or rack) */
-    res = m_board.checkRound(oRound, getNTurns() == 0);
+    res = m_board.checkRound(oRound, m_history.getSize() == 0);
     if (res != 0)
         return res + 4;
 
Index: eliot/game/game.h
diff -u eliot/game/game.h:1.23 eliot/game/game.h:1.24
--- eliot/game/game.h:1.23      Mon Dec 26 18:09:52 2005
+++ eliot/game/game.h   Mon Dec 26 22:58:58 2005
@@ -26,6 +26,7 @@
 #include <iostream>
 #include "bag.h"
 #include "board.h"
+#include "history.h"
 
 class Player;
 class PlayedRack;
@@ -124,19 +125,15 @@
      *    3 : the rack cannot be completed (Game_*_setrackrandom only)
      *************************/
     static const int RACK_SIZE;
-    enum set_rack_mode {RACK_ALL, RACK_NEW};
+    enum set_rack_mode {RACK_ALL, RACK_NEW, RACK_MANUAL};
+    int setRack(int player, set_rack_mode mode, bool check, const string& str);
+    string getPlayerRack(int, bool = false) const;
 
     /**
      * Methods to access already played words.
      * The int parameter should be 0 <= int < getNTurns()
      */
-    int getNTurns() const     { return m_history.size(); }
-    string getPlayedRack(int) const;
-    string getPlayedWord(int) const;
-    string getPlayedCoords(int num) const;
-    int getPlayedPoints(int) const;
-    int getPlayedBonus(int) const;
-    int getPlayedPlayer(int) const;
+    const History& getHistory() { return m_history; }
 
     /**
      * Methods to access players.
@@ -147,15 +144,12 @@
     virtual void addHumanPlayer();
     // TODO: Ability to specify which kind of AI player is wanted
     virtual void addAIPlayer();
-    string getPlayerRack(int, bool = false) const;
-
     int  currPlayer() const     { return m_currPlayer; }
 
     /**
      * Game handling
      */
     virtual int start() = 0;
-    virtual int setRackRandom(int, bool, set_rack_mode) = 0;
     virtual int play(const string &iCoord, const string &iWord) = 0;
     virtual int endTurn() = 0;
 
@@ -184,7 +178,7 @@
      * History of the game.
      * The vector is indexed by the number of turns in the game
      */
-    vector<Turn*> m_history;
+    History m_history;
 
     int m_points;
 




reply via email to

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