eliot-dev
[Top][All Lists]
Advanced

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

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


From: eliot-dev
Subject: [Eliot-dev] eliot game/duplicate.cpp game/duplicate.h game/...
Date: Sun, 14 Sep 2008 17:56:19 +0000

CVSROOT:        /cvsroot/eliot
Module name:    eliot
Changes by:     Olivier Teulière <ipkiss>      08/09/14 17:56:19

Modified files:
        game           : duplicate.cpp duplicate.h game.cpp game.h 
                         pldrack.cpp pldrack.h 
        qt             : player_widget.cpp player_widget.h 
        qt/ui          : player_widget.ui 

Log message:
         - Support shuffling the rack of the current player
         - More intuitive players management (in particular when there are 
several
           human players)

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.cpp?cvsroot=eliot&r1=1.17&r2=1.18
http://cvs.savannah.gnu.org/viewcvs/eliot/game/duplicate.h?cvsroot=eliot&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.cpp?cvsroot=eliot&r1=1.41&r2=1.42
http://cvs.savannah.gnu.org/viewcvs/eliot/game/game.h?cvsroot=eliot&r1=1.35&r2=1.36
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.cpp?cvsroot=eliot&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/eliot/game/pldrack.h?cvsroot=eliot&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.cpp?cvsroot=eliot&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/player_widget.h?cvsroot=eliot&r1=1.5&r2=1.6
http://cvs.savannah.gnu.org/viewcvs/eliot/qt/ui/player_widget.ui?cvsroot=eliot&r1=1.3&r2=1.4

Patches:
Index: game/duplicate.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.cpp,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -b -r1.17 -r1.18
--- game/duplicate.cpp  8 Jan 2008 13:52:37 -0000       1.17
+++ game/duplicate.cpp  14 Sep 2008 17:56:18 -0000      1.18
@@ -271,6 +271,15 @@
              m_hasPlayed[m_currPlayer]);
 }
 
+
+bool Duplicate::hasPlayed(unsigned int p) const
+{
+    ASSERT(p < getNPlayers(), "Wrong player number");
+
+    map<unsigned int, bool>::const_iterator it = m_hasPlayed.find(p);
+    return it != m_hasPlayed.end() && it->second;
+}
+
 /// Local Variables:
 /// mode: c++
 /// mode: hs-minor

Index: game/duplicate.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/duplicate.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- game/duplicate.h    8 Jan 2008 13:52:37 -0000       1.13
+++ game/duplicate.h    14 Sep 2008 17:56:18 -0000      1.14
@@ -90,6 +90,10 @@
     /// Switch to the next human player who has not played yet
     void nextHumanPlayer();
 
+    /// Return true if the player has played for the current turn
+    // XXX: not very nice API, should be a player property...
+    virtual bool hasPlayed(unsigned int player) const;
+
 private:
     // Private constructor to force using the GameFactory class
     Duplicate(const Dictionary &iDic);
@@ -127,7 +131,7 @@
     void endGame();
 
     // m_hasPlayed[p] is true iff player p has played for this turn
-    map<int, bool> m_hasPlayed;
+    map<unsigned int, bool> m_hasPlayed;
 };
 
 #endif /* _DUPLICATE_H_ */

Index: game/game.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.cpp,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -b -r1.41 -r1.42
--- game/game.cpp       13 Sep 2008 21:32:46 -0000      1.41
+++ game/game.cpp       14 Sep 2008 17:56:18 -0000      1.42
@@ -204,6 +204,14 @@
 }
 
 
+void Game::shuffleRack()
+{
+    PlayedRack pld = getCurrentPlayer().getCurrentRack();
+    pld.shuffle();
+    m_players[currPlayer()]->setCurrentRack(pld);
+}
+
+
 void Game::realBag(Bag &ioBag) const
 {
     vector<Tile> tiles;

Index: game/game.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/game.h,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -b -r1.35 -r1.36
--- game/game.h 13 Sep 2008 21:32:46 -0000      1.35
+++ game/game.h 14 Sep 2008 17:56:18 -0000      1.36
@@ -158,6 +158,13 @@
      */
     int back(unsigned int iTurn);
 
+    /// Shuffle the rack of the current player
+    void shuffleRack();
+
+    /// Return true if the player has played for the current turn
+    // XXX: not very nice API, should be a player property...
+    virtual bool hasPlayed(unsigned int player) const { return player != 
currPlayer(); }
+
     /***************
      * Saved games handling
      ***************/

Index: game/pldrack.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.cpp,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- game/pldrack.cpp    26 Jan 2008 10:10:51 -0000      1.11
+++ game/pldrack.cpp    14 Sep 2008 17:56:18 -0000      1.12
@@ -192,6 +192,15 @@
 }
 
 
+void PlayedRack::shuffle()
+{
+    m_newTiles.insert(m_newTiles.end(),
+                      m_oldTiles.begin(), m_oldTiles.end());
+    m_oldTiles.clear();
+    shuffleNew();
+}
+
+
 wstring PlayedRack::toString(display_mode mode) const
 {
     wstring s;

Index: game/pldrack.h
===================================================================
RCS file: /cvsroot/eliot/eliot/game/pldrack.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- game/pldrack.h      8 Jan 2008 13:52:39 -0000       1.13
+++ game/pldrack.h      14 Sep 2008 17:56:18 -0000      1.14
@@ -75,6 +75,8 @@
 
     /// Randomly change the order of the "new" tiles
     void shuffleNew();
+    /// Randomly change the order of all the tiles (they all become "new")
+    void shuffle();
 
     enum display_mode
     {

Index: qt/player_widget.cpp
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.cpp,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- qt/player_widget.cpp        13 Sep 2008 21:32:47 -0000      1.8
+++ qt/player_widget.cpp        14 Sep 2008 17:56:18 -0000      1.9
@@ -28,6 +28,7 @@
 #include "qtcommon.h"
 #include "game.h"
 #include "freegame.h"
+#include "duplicate.h"
 #include "player.h"
 #include "pldrack.h"
 #include "coord.h"
@@ -134,12 +135,17 @@
     lineEditPlay->clear();
     lineEditCoords->clear();
     lineEditChange->clear();
+
+    // Do not allow messing with AI players or with players who already played
+    setEnabled(!m_game->hasPlayed(m_player) &&
+               m_game->getPlayer(m_player).isHuman());
 }
 
 
 void PlayerWidget::on_pushButtonShuffle_clicked()
 {
-    // TODO: (not supported in the core yet)
+    m_game->shuffleRack();
+    emit gameUpdated();
 }
 
 
@@ -367,11 +373,15 @@
 PlayerTabWidget::PlayerTabWidget(QWidget *parent)
     : QTabWidget(parent)
 {
+    QObject::connect(this, SIGNAL(currentChanged(int)),
+                     this, SLOT(changeCurrentPlayer(int)));
 }
 
 
 void PlayerTabWidget::setGame(Game *iGame)
 {
+    m_game = iGame;
+
     // Remove all the tabs
     int nbTabs = count();
     for (int i = 0; i < nbTabs; ++i)
@@ -414,7 +424,12 @@
                 QObject::connect(p, SIGNAL(gameUpdated()),
                                  this, SIGNAL(gameUpdated()));
                 addTab(p, qfw(player.getName()));
+                // Switching to a tab corresponding to an AI player
+                // is forbidden
+                if (!player.isHuman())
+                    setTabEnabled(i, false);
             }
+            setCurrentIndex(iGame->currPlayer());
         }
     }
 }
@@ -422,7 +437,20 @@
 
 void PlayerTabWidget::refresh()
 {
+    if (m_game)
+        setCurrentIndex(m_game->currPlayer());
     emit refreshSignal();
 }
 
 
+void PlayerTabWidget::changeCurrentPlayer(int p)
+{
+    // Change the active player when the active tab changes
+    // (only in duplicate mode)
+    Duplicate *dupli = dynamic_cast<Duplicate*>(m_game);
+    if (dupli && widget(p)->isEnabled())
+    {
+        dupli->setPlayer(p);
+    }
+}
+

Index: qt/player_widget.h
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/player_widget.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- qt/player_widget.h  7 Sep 2008 21:06:17 -0000       1.5
+++ qt/player_widget.h  14 Sep 2008 17:56:19 -0000      1.6
@@ -85,6 +85,13 @@
     void refreshSignal();
     void gameUpdated();
     void notifyProblem(QString iMsg);
+
+private slots:
+    void changeCurrentPlayer(int);
+
+private:
+    /// Encapsulated game, can be NULL
+    Game *m_game;
 };
 
 #endif

Index: qt/ui/player_widget.ui
===================================================================
RCS file: /cvsroot/eliot/eliot/qt/ui/player_widget.ui,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- qt/ui/player_widget.ui      7 Sep 2008 21:06:18 -0000       1.3
+++ qt/ui/player_widget.ui      14 Sep 2008 17:56:19 -0000      1.4
@@ -26,9 +26,6 @@
    </item>
    <item row="0" column="4" >
     <widget class="QPushButton" name="pushButtonShuffle" >
-     <property name="enabled" >
-      <bool>false</bool>
-     </property>
      <property name="text" >
       <string>_("Shuffle")</string>
      </property>




reply via email to

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