eliot-dev
[Top][All Lists]
Advanced

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

[Eliot-dev] eliot/game command.h game_move_cmd.cpp game_mov...


From: Olivier Teulière
Subject: [Eliot-dev] eliot/game command.h game_move_cmd.cpp game_mov...
Date: Sun, 23 Nov 2008 17:02:34 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/11/23 17:02:34

Modified files:
        game           : command.h game_move_cmd.cpp game_move_cmd.h 
                         navigation.cpp navigation.h player_move_cmd.cpp 
                         player_move_cmd.h player_rack_cmd.cpp 
                         player_rack_cmd.h turn_cmd.cpp turn_cmd.h 

Log message:
        Added toString() methods to the commands to ease debugging

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/command.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_move_cmd.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game_move_cmd.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/navigation.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/navigation.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_move_cmd.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_move_cmd.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_rack_cmd.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/player_rack_cmd.h?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn_cmd.cpp?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn_cmd.h?cvsroot=eliot&r1=1.2&r2=1.3

Patches:
Index: command.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/command.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- command.h   23 Nov 2008 08:18:05 -0000      1.1
+++ command.h   23 Nov 2008 17:02:33 -0000      1.2
@@ -21,6 +21,10 @@
 #ifndef _COMMAND_H
 #define _COMMAND_H
 
+#include <string>
+
+using std::wstring;
+
 
 /**
  * This abstract class is the parent of all classes implementing the Command
@@ -54,6 +58,11 @@
          */
         bool isExecuted() const { return m_executed; }
 
+        /**
+         * Description of the command, for debugging purposes
+         */
+        virtual wstring toString() const = 0;
+
     protected:
         virtual void doExecute() = 0;
         virtual void doUndo() = 0;

Index: game_move_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_move_cmd.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- game_move_cmd.cpp   23 Nov 2008 16:58:31 -0000      1.2
+++ game_move_cmd.cpp   23 Nov 2008 17:02:33 -0000      1.3
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include <sstream>
+
 #include "game_move_cmd.h"
 #include "player.h"
 #include "game.h"
@@ -160,3 +162,12 @@
     }
 }
 
+
+wstring GameMoveCmd::toString() const
+{
+    wostringstream oss;
+    oss << L"GameMoveCmd (move: " << m_move.toString() << L", rack: "
+        << m_moveRack.toString() << L")";
+    return oss.str();
+}
+

Index: game_move_cmd.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game_move_cmd.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- game_move_cmd.h     23 Nov 2008 08:18:07 -0000      1.1
+++ game_move_cmd.h     23 Nov 2008 17:02:33 -0000      1.2
@@ -47,6 +47,8 @@
                     const PlayedRack &iMoveRack,
                     unsigned int iPlayerId);
 
+        virtual wstring toString() const;
+
     protected:
         virtual void doExecute();
         virtual void doUndo();

Index: navigation.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/navigation.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- navigation.cpp      23 Nov 2008 16:55:28 -0000      1.1
+++ navigation.cpp      23 Nov 2008 17:02:33 -0000      1.2
@@ -19,10 +19,12 @@
  *****************************************************************************/
 
 #include <boost/foreach.hpp>
+#include <iostream>
 
 #include "navigation.h"
 #include "turn_cmd.h"
 #include "debug.h"
+#include "encoding.h"
 
 
 Navigation::Navigation()
@@ -116,3 +118,13 @@
            "After removing the next turns, we should be at the last turn");
 }
 
+
+void Navigation::print() const
+{
+    cout << "=== Commands history ===" << endl;
+    BOOST_FOREACH(Command *c, m_turnCommands)
+    {
+        cout << convertToMb(c->toString()) << endl;
+    }
+}
+

Index: navigation.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/navigation.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- navigation.h        23 Nov 2008 16:55:29 -0000      1.1
+++ navigation.h        23 Nov 2008 17:02:33 -0000      1.2
@@ -52,10 +52,14 @@
          */
         void clearFuture();
 
+        /**
+         * Print the contents of the commands history, to ease debugging
+         */
+        void print() const;
+
     private:
         vector<TurnCmd *> m_turnCommands;
         unsigned int m_currTurn;
-
 };
 
 #endif

Index: player_move_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player_move_cmd.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_move_cmd.cpp 23 Nov 2008 08:18:09 -0000      1.1
+++ player_move_cmd.cpp 23 Nov 2008 17:02:33 -0000      1.2
@@ -21,6 +21,7 @@
 #include "player_move_cmd.h"
 #include "player.h"
 #include "rack.h"
+#include <sstream>
 
 
 PlayerMoveCmd::PlayerMoveCmd(Player &ioPlayer, const Move &iMove)
@@ -53,3 +54,12 @@
     // TODO: restore rack?
 }
 
+
+wstring PlayerMoveCmd::toString() const
+{
+    wostringstream oss;
+    oss << L"PlayerMoveCmd (player " << m_player.getId() << L"): "
+        << m_move.toString();
+    return oss.str();
+}
+

Index: player_move_cmd.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player_move_cmd.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_move_cmd.h   23 Nov 2008 08:18:09 -0000      1.1
+++ player_move_cmd.h   23 Nov 2008 17:02:33 -0000      1.2
@@ -44,6 +44,8 @@
     public:
         PlayerMoveCmd(Player &ioPlayer, const Move &iMove);
 
+        virtual wstring toString() const;
+
     protected:
         virtual void doExecute();
         virtual void doUndo();

Index: player_rack_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player_rack_cmd.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_rack_cmd.cpp 23 Nov 2008 08:18:09 -0000      1.1
+++ player_rack_cmd.cpp 23 Nov 2008 17:02:33 -0000      1.2
@@ -18,6 +18,8 @@
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  *****************************************************************************/
 
+#include <sstream>
+
 #include "player_rack_cmd.h"
 #include "player.h"
 
@@ -43,3 +45,12 @@
     m_player.setCurrentRack(m_oldRack);
 }
 
+
+wstring PlayerRackCmd::toString() const
+{
+    wostringstream oss;
+    oss << L"PlayerRackCmd (player " << m_player.getId() << L"): "
+        << m_newRack.toString();
+    return oss.str();
+}
+

Index: player_rack_cmd.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/player_rack_cmd.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- player_rack_cmd.h   23 Nov 2008 08:18:09 -0000      1.1
+++ player_rack_cmd.h   23 Nov 2008 17:02:33 -0000      1.2
@@ -36,6 +36,8 @@
     public:
         PlayerRackCmd(Player &ioPlayer, const PlayedRack &iNewRack);
 
+        virtual wstring toString() const;
+
     protected:
         virtual void doExecute();
         virtual void doUndo();

Index: turn_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn_cmd.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- turn_cmd.cpp        23 Nov 2008 16:55:29 -0000      1.2
+++ turn_cmd.cpp        23 Nov 2008 17:02:33 -0000      1.3
@@ -19,6 +19,7 @@
  *****************************************************************************/
 
 #include <boost/foreach.hpp>
+#include <sstream>
 
 #include "turn_cmd.h"
 #include "player.h"
@@ -67,3 +68,15 @@
     }
 }
 
+
+wstring TurnCmd::toString() const
+{
+    wostringstream oss;
+    oss << L"TurnCmd:" << endl;
+    BOOST_FOREACH(Command *cmd, m_commands)
+    {
+        oss << L"    " << cmd->toString() << endl;
+    }
+    return oss.str();
+}
+

Index: turn_cmd.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn_cmd.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- turn_cmd.h  23 Nov 2008 16:55:29 -0000      1.2
+++ turn_cmd.h  23 Nov 2008 17:02:34 -0000      1.3
@@ -46,6 +46,8 @@
 
         bool isEmpty() const { return m_commands.empty(); }
 
+        virtual wstring toString() const;
+
     protected:
         virtual void doExecute();
         virtual void doUndo();




reply via email to

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