Keep track of move amount
This commit is contained in:
parent
fab342c71f
commit
7ef0ade0b3
|
@ -53,6 +53,8 @@ ApplicationWindow {
|
|||
ScoreBar {
|
||||
id: scoreBar
|
||||
|
||||
moves: GameState.moveAmount
|
||||
|
||||
height: Math.max(parent.height * 0.08, 50)
|
||||
anchors.top: parent.top
|
||||
anchors.left: parent.left
|
||||
|
|
|
@ -53,6 +53,7 @@ void GameState::dealCards() {
|
|||
emit throwawayPileChanged();
|
||||
emit columnsChanged();
|
||||
emit foundationChanged();
|
||||
emit moveAmountChanged();
|
||||
}
|
||||
|
||||
void GameState::setupWinningDeck() {
|
||||
|
@ -84,6 +85,7 @@ void GameState::setupWinningDeck() {
|
|||
emit throwawayPileChanged();
|
||||
emit columnsChanged();
|
||||
emit foundationChanged();
|
||||
emit moveAmountChanged();
|
||||
}
|
||||
|
||||
bool GameState::drawNextCard() {
|
||||
|
@ -104,6 +106,7 @@ bool GameState::drawNextCard() {
|
|||
m_throwawayPile.append(m_drawPile.takeFirst());
|
||||
qDebug() << "> Drawn card: " << m_throwawayPile.last()->toString();
|
||||
|
||||
incrementMoveAmt();
|
||||
emit drawPileChanged();
|
||||
emit throwawayPileChanged();
|
||||
return true;
|
||||
|
@ -133,6 +136,7 @@ bool GameState::moveThrownCardToColumn(int columnId) {
|
|||
m_throwawayPile.removeLast();
|
||||
qDebug() << "> Moving complete";
|
||||
|
||||
incrementMoveAmt();
|
||||
emit throwawayPileChanged();
|
||||
emit columnsChanged();
|
||||
return true;
|
||||
|
@ -162,6 +166,7 @@ bool GameState::moveThrownCardToFoundation(int foundationId) {
|
|||
m_throwawayPile.removeLast();
|
||||
qDebug() << "> Moving complete";
|
||||
|
||||
incrementMoveAmt();
|
||||
emit throwawayPileChanged();
|
||||
emit foundationChanged();
|
||||
return true;
|
||||
|
@ -208,6 +213,7 @@ bool GameState::moveColumnCardToColumn(int fromColumnId, int toColumnId, int fro
|
|||
ensureColumnRevealed(fromColumnId);
|
||||
qDebug() << "> Moving complete";
|
||||
|
||||
incrementMoveAmt();
|
||||
emit columnsChanged();
|
||||
return true;
|
||||
}
|
||||
|
@ -241,6 +247,7 @@ bool GameState::moveColumnCardToFoundation(int columnId, int foundationId) {
|
|||
ensureColumnRevealed(columnId);
|
||||
qDebug() << "> Moving complete";
|
||||
|
||||
incrementMoveAmt();
|
||||
emit columnsChanged();
|
||||
emit foundationChanged();
|
||||
return true;
|
||||
|
@ -273,6 +280,7 @@ bool GameState::autoMoveThrownCard() {
|
|||
// NOTE: consider returning what changed from tryAutoMoveSingleCard
|
||||
emit columnsChanged();
|
||||
emit foundationChanged();
|
||||
incrementMoveAmt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -313,6 +321,7 @@ bool GameState::autoMoveColumnCard(int columnId, int cardIndex) {
|
|||
// to be safe, emit a change signal for it too
|
||||
// NOTE: consider returning what changed from tryAutoMoveSingleCard
|
||||
emit foundationChanged();
|
||||
incrementMoveAmt();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -339,6 +348,7 @@ bool GameState::autoMoveColumnCard(int columnId, int cardIndex) {
|
|||
|
||||
ensureColumnRevealed(columnId);
|
||||
|
||||
incrementMoveAmt();
|
||||
emit columnsChanged();
|
||||
return true;
|
||||
}
|
||||
|
@ -432,6 +442,8 @@ void GameState::cleanupBoard(bool emitChanges) {
|
|||
column.clear();
|
||||
}
|
||||
|
||||
m_moveAmt = 0;
|
||||
|
||||
// Note that we don't need to reset gameWon from here, as it's
|
||||
// auto-checked from onFoundationChanged, which the emits trigger
|
||||
|
||||
|
@ -440,6 +452,7 @@ void GameState::cleanupBoard(bool emitChanges) {
|
|||
emit throwawayPileChanged();
|
||||
emit foundationChanged();
|
||||
emit columnsChanged();
|
||||
emit moveAmountChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -617,6 +630,11 @@ void GameState::ensureColumnRevealed(int columnId) {
|
|||
qDebug() << "Revealed card " << col->card()->toString() << " in column " << columnId;
|
||||
}
|
||||
|
||||
void GameState::incrementMoveAmt() {
|
||||
m_moveAmt++;
|
||||
emit moveAmountChanged();
|
||||
}
|
||||
|
||||
std::pair<std::optional<bool>, int> GameState::canWinThroughSimulation(QSet<QString>& visitedStates, QElapsedTimer timer) const {
|
||||
if (m_gameWon)
|
||||
return std::make_pair(true, 0); // Already won at depth 0
|
||||
|
@ -803,6 +821,10 @@ QVariantList GameState::foundation() const {
|
|||
return lst;
|
||||
}
|
||||
|
||||
int GameState::moveAmount() const {
|
||||
return m_moveAmt;
|
||||
}
|
||||
|
||||
bool GameState::gameWon() const {
|
||||
return m_gameWon;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ class GameState : public QObject {
|
|||
Q_PROPERTY(QVariantList throwawayPile READ throwawayPile NOTIFY throwawayPileChanged)
|
||||
Q_PROPERTY(QVariantList columns READ columns NOTIFY columnsChanged)
|
||||
Q_PROPERTY(QVariantList foundation READ foundation NOTIFY foundationChanged)
|
||||
Q_PROPERTY(int moveAmount READ moveAmount NOTIFY moveAmountChanged)
|
||||
Q_PROPERTY(bool gameWon READ gameWon NOTIFY gameWonChanged)
|
||||
|
||||
public:
|
||||
|
@ -32,6 +33,7 @@ class GameState : public QObject {
|
|||
QVariantList throwawayPile() const;
|
||||
QVariantList columns() const;
|
||||
QVariantList foundation() const;
|
||||
int moveAmount() const;
|
||||
bool gameWon() const;
|
||||
|
||||
// General functions
|
||||
|
@ -55,6 +57,7 @@ class GameState : public QObject {
|
|||
void throwawayPileChanged();
|
||||
void columnsChanged();
|
||||
void foundationChanged();
|
||||
void moveAmountChanged();
|
||||
void gameWonChanged();
|
||||
|
||||
private slots:
|
||||
|
@ -65,6 +68,7 @@ class GameState : public QObject {
|
|||
QList<PlayingCard*> m_throwawayPile;
|
||||
QList<QList<ColumnSlot*>> m_columns;
|
||||
QList<QList<PlayingCard*>> m_foundation;
|
||||
int m_moveAmt;
|
||||
bool m_gameWon;
|
||||
|
||||
GameState* clone() const;
|
||||
|
@ -78,6 +82,7 @@ class GameState : public QObject {
|
|||
bool isColumnMoveValid(const PlayingCard& cardToMove, int columnId) const;
|
||||
|
||||
void ensureColumnRevealed(int columnId);
|
||||
void incrementMoveAmt();
|
||||
|
||||
std::pair<std::optional<bool>, int> canWinThroughSimulation(QSet<QString>& visitedStates, QElapsedTimer timer) const;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue