eliot-dev
[Top][All Lists]
Advanced

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

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


From: Olivier Teulière
Subject: [Eliot-dev] eliot/game command.cpp command.h duplicate.cpp ...
Date: Sun, 30 Nov 2008 20:55:46 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/11/30 20:55:46

Modified files:
        game           : command.cpp command.h duplicate.cpp duplicate.h 
                         freegame.cpp freegame.h navigation.cpp 
                         training.cpp turn_cmd.cpp turn_cmd.h 

Log message:
        Added auto-execution of commands when clearing future commands.
        The goal is to automatically replay commands involving AI, so that the 
user cannot be 'blocked'.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/command.cpp?cvsroot=eliot&r1=1.1&r2=1.2
http://cvs.savannah.gnu.org/viewcvs/eliot/game/command.h?cvsroot=eliot&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.cpp?cvsroot=eliot&r1=1.29&r2=1.30
http://cvs.savannah.gnu.org/viewcvs/eliot/game/freegame.h?cvsroot=eliot&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/eliot/game/navigation.cpp?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/game/training.cpp?cvsroot=eliot&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn_cmd.cpp?cvsroot=eliot&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/eliot/game/turn_cmd.h?cvsroot=eliot&r1=1.3&r2=1.4

Patches:
Index: command.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/command.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- command.cpp 23 Nov 2008 08:18:04 -0000      1.1
+++ command.cpp 30 Nov 2008 20:55:45 -0000      1.2
@@ -23,7 +23,7 @@
 
 
 Command::Command()
-    : m_executed(false)
+    : m_executed(false), m_autoExecution(true)
 {
 }
 

Index: command.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/command.h,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- command.h   23 Nov 2008 17:02:33 -0000      1.2
+++ command.h   30 Nov 2008 20:55:46 -0000      1.3
@@ -59,6 +59,17 @@
         bool isExecuted() const { return m_executed; }
 
         /**
+         * Mark the command as auto-executable, which means that it will
+         * be automatically executed if the commands history is cleared
+         * just before this command.
+         * Auto-executable commands correspond to commands for AI players,
+         * for which the user cannot change the behaviour.
+         */
+        void setAutoExecution(bool autoExec) { m_autoExecution = autoExec; }
+        /// Return true if the command is auto-executable
+        virtual bool isAutoExecution() const { return m_autoExecution; }
+
+        /**
          * Description of the command, for debugging purposes
          */
         virtual wstring toString() const = 0;
@@ -69,6 +80,7 @@
 
     private:
         bool m_executed;
+        bool m_autoExecution;
 };
 
 #endif

Index: duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- duplicate.cpp       30 Nov 2008 20:51:42 -0000      1.28
+++ duplicate.cpp       30 Nov 2008 20:55:46 -0000      1.29
@@ -61,12 +61,12 @@
     if (res == 0)
     {
         // Everything is OK, we can play the word
-        recordPlayerMove(Move(round), currPlayer);
+        recordPlayerMove(Move(round), currPlayer, true);
     }
     else
     {
         // Record the invalid move of the player
-        recordPlayerMove(Move(iWord, iCoord), currPlayer);
+        recordPlayerMove(Move(iWord, iCoord), currPlayer, true);
     }
 
     // Little hack to handle duplicate games with only AI players.
@@ -93,7 +93,7 @@
         ASSERT(false, "AI tried to cheat!");
     }
 
-    recordPlayerMove(move, *player);
+    recordPlayerMove(move, *player, false);
 }
 
 
@@ -164,12 +164,14 @@
 }
 
 
-void Duplicate::recordPlayerMove(const Move &iMove, Player &ioPlayer)
+void Duplicate::recordPlayerMove(const Move &iMove, Player &ioPlayer, bool 
isForHuman)
 {
     Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
+    pCmd->setAutoExecution(!isForHuman);
     accessNavigation().addAndExecute(pCmd);
 
     Command *pCmd2 = new MarkPlayedCmd(*this, ioPlayer.getId(), true);
+    pCmd2->setAutoExecution(!isForHuman);
     accessNavigation().addAndExecute(pCmd2);
 }
 

Index: duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.h,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- duplicate.h 30 Nov 2008 20:51:42 -0000      1.19
+++ duplicate.h 30 Nov 2008 20:55:46 -0000      1.20
@@ -95,7 +95,7 @@
     Duplicate(const Dictionary &iDic);
 
     /// Record a player move
-    void recordPlayerMove(const Move &iMove, Player &ioPlayer);
+    void recordPlayerMove(const Move &iMove, Player &ioPlayer, bool 
isForHuman);
 
     /// Make the AI player whose ID is p play its turn
     void playAI(unsigned int p);

Index: freegame.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.cpp,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -b -r1.29 -r1.30
--- freegame.cpp        23 Nov 2008 17:07:42 -0000      1.29
+++ freegame.cpp        30 Nov 2008 20:55:46 -0000      1.30
@@ -66,14 +66,14 @@
         Move move(round);
 
         // Update the rack and the score of the current player
-        recordPlayerMove(move, *m_players[m_currPlayer]);
+        recordPlayerMove(move, *m_players[m_currPlayer], true);
     }
     else
     {
         Move move(iWord, iCoord);
 
         // Record the invalid move of the player
-        recordPlayerMove(move, *m_players[m_currPlayer]);
+        recordPlayerMove(move, *m_players[m_currPlayer], true);
     }
 
     // Next turn
@@ -100,15 +100,17 @@
     }
 
     // Update the rack and the score of the current player
-    recordPlayerMove(move, *player);
+    recordPlayerMove(move, *player, false);
 
     endTurn();
 }
 
 
-void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer)
+void FreeGame::recordPlayerMove(const Move &iMove, Player &ioPlayer,
+                                bool isForHuman)
 {
     Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
+    pCmd->setAutoExecution(!isForHuman);
     accessNavigation().addAndExecute(pCmd);
 }
 
@@ -275,7 +277,7 @@
 
     Move move(iToChange);
     // End the player's turn
-    recordPlayerMove(move, player);
+    recordPlayerMove(move, player, true);
 
     // Next game turn
     endTurn();

Index: freegame.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/freegame.h,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- freegame.h  23 Nov 2008 17:07:42 -0000      1.16
+++ freegame.h  30 Nov 2008 20:55:46 -0000      1.17
@@ -86,7 +86,7 @@
     void playAI(unsigned int p);
 
     /// Record a player move
-    void recordPlayerMove(const Move &iMove, Player &ioPlayer);
+    void recordPlayerMove(const Move &iMove, Player &ioPlayer, bool 
isForHuman);
 
     /// Finish the current turn
     int endTurn();

Index: navigation.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/navigation.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- navigation.cpp      30 Nov 2008 20:51:05 -0000      1.5
+++ navigation.cpp      30 Nov 2008 20:55:46 -0000      1.6
@@ -145,6 +145,11 @@
 
 void Navigation::clearFuture()
 {
+    // Replay the auto-execution turns
+    // (i.e. turns where only the AI was involved)
+    while (!isLastTurn() && m_turnCommands[m_currTurn]->isAutoExecution())
+        nextTurn();
+
     // When there is no future, don't do anything
     if (isLastTurn())
         return;

Index: training.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/training.cpp,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- training.cpp        23 Nov 2008 17:08:12 -0000      1.28
+++ training.cpp        30 Nov 2008 20:55:46 -0000      1.29
@@ -59,6 +59,7 @@
     const PlayedRack &newRack =
         helperSetRackRandom(getCurrentPlayer().getCurrentRack(), iCheck, mode);
     Command *pCmd = new PlayerRackCmd(*m_players[m_currPlayer], newRack);
+    pCmd->setAutoExecution(false);
     accessNavigation().addAndExecute(pCmd);
 }
 
@@ -130,6 +131,7 @@
     // (called in this class in endTurn()).
     // See the big comment in game.cpp, line 96
     Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove);
+    pCmd->setAutoExecution(false);
     accessNavigation().addAndExecute(pCmd);
 }
 

Index: turn_cmd.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/turn_cmd.cpp,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- turn_cmd.cpp        23 Nov 2008 17:02:33 -0000      1.3
+++ turn_cmd.cpp        30 Nov 2008 20:55:46 -0000      1.4
@@ -69,6 +69,17 @@
 }
 
 
+bool TurnCmd::isAutoExecution() const
+{
+    BOOST_FOREACH(Command *cmd, m_commands)
+    {
+        if (!cmd->isAutoExecution())
+            return false;
+    }
+    return true;
+}
+
+
 wstring TurnCmd::toString() const
 {
     wostringstream oss;

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




reply via email to

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