diff --git a/dealer.h b/dealer.h --- a/dealer.h +++ b/dealer.h @@ -110,7 +110,7 @@ virtual bool isGameWon() const; bool allowedToStartNewGame(); - int moveCount() const; + virtual int moveCount() const; void saveFile( QIODevice * io ); bool loadFile( QIODevice * io ); @@ -241,7 +241,9 @@ QTimer m_dropTimer; int m_dealNumber; +protected: int m_loadedMoveCount; +private: int m_neededFutureMoves; int m_supportedActions; @@ -275,10 +277,12 @@ bool m_newCardsQueued; bool m_takeStateQueued; +protected: QStack m_undoStack; GameState * m_currentState; QStack m_redoStack; QHash m_lastKnownCardStates; +private: QList > m_multiStepMoves; int m_multiStepDuration; diff --git a/freecell.h b/freecell.h --- a/freecell.h +++ b/freecell.h @@ -48,6 +48,7 @@ public: explicit Freecell( const DealerInfo * di ); void initialize() override; + int moveCount() const override; protected: bool checkAdd(const PatPile * pile, const QList & oldCards, const QList & newCards) const override; diff --git a/freecell.cpp b/freecell.cpp --- a/freecell.cpp +++ b/freecell.cpp @@ -98,6 +98,24 @@ setNeededFutureMoves( 4 ); // reserve some } +int Freecell::moveCount() const +{ + int count = 0; + // For every move that was done so far, + for (int i = 0; i< m_undoStack.size(); ++i) { + // add the number of cards that were moved + count += m_undoStack.at(i)->changes.size(); + } + // Do the same for the current state + count += m_currentState ? m_currentState->changes.size() : 0; + // Finally, add the number of moves from the save state. + count += m_loadedMoveCount; + // Setting up the initial game state creates a state with a run containing 8 changes + // This initial setup should not be part of the moveCount, thus we subtract it + count -= 8; + return count; +} + void Freecell::restart( const QList & cards ) {