diff --git a/clock.cpp b/clock.cpp --- a/clock.cpp +++ b/clock.cpp @@ -103,7 +103,7 @@ { QPointF initPos = (2 * center + target[(i + 2) % 12]->pos()) / 3; addCardForDeal( target[i], c, true, initPos ); - c = 0; + c = nullptr; break; } } diff --git a/dealer.h b/dealer.h --- a/dealer.h +++ b/dealer.h @@ -38,7 +38,6 @@ #ifndef DEALER_H #define DEALER_H -class CardDiff; class DealerInfo; #include "gamestate.h" class MessageBox; @@ -57,7 +56,6 @@ #include #include #include -class QDomDocument; class DealerScene : public KCardScene diff --git a/dealer.cpp b/dealer.cpp --- a/dealer.cpp +++ b/dealer.cpp @@ -107,7 +107,7 @@ } } - int readIntAttribute( const QXmlStreamReader & xml, const QString & key, bool * ok = 0 ) + int readIntAttribute( const QXmlStreamReader & xml, const QString & key, bool * ok = nullptr ) { QStringRef value = xml.attributes().value( key ); return QString::fromRawData( value.data(), value.length() ).toInt( ok ); @@ -539,9 +539,9 @@ DealerScene::DealerScene( const DealerInfo * di ) : m_di( di ), - m_solver( 0 ), - m_solverThread( 0 ), - m_peekedCard( 0 ), + m_solver( nullptr ), + m_solverThread( nullptr ), + m_peekedCard( nullptr ), m_dealNumber( 0 ), m_loadedMoveCount( 0 ), m_neededFutureMoves( 1 ), @@ -567,7 +567,7 @@ m_dropQueued( false ), m_newCardsQueued( false ), m_takeStateQueued( false ), - m_currentState( 0 ) + m_currentState( nullptr ) { setItemIndexMethod(QGraphicsScene::NoIndex); @@ -601,9 +601,9 @@ if ( m_solverThread ) m_solverThread->abort(); delete m_solverThread; - m_solverThread = 0; + m_solverThread = nullptr; delete m_solver; - m_solver = 0; + m_solver = nullptr; qDeleteAll( m_undoStack ); delete m_currentState; qDeleteAll( m_redoStack ); @@ -874,7 +874,7 @@ qDeleteAll( m_undoStack ); m_undoStack.clear(); delete m_currentState; - m_currentState = 0; + m_currentState = nullptr; qDeleteAll( m_redoStack ); m_redoStack.clear(); m_lastKnownCardStates.clear(); @@ -1089,7 +1089,7 @@ { e->accept(); updatePileLayout( m_peekedCard->pile(), DURATION_FANCYSHOW ); - m_peekedCard = 0; + m_peekedCard = nullptr; } else { @@ -1712,7 +1712,7 @@ delete m_solver; delete m_solverThread; m_solver = s; - m_solverThread = 0; + m_solverThread = nullptr; } bool DealerScene::isGameWon() const @@ -1892,7 +1892,7 @@ { p.save(); p.setTransform( item->deviceTransform( p.worldTransform() ), false ); - item->paint( &p, 0 ); + item->paint( &p, nullptr ); p.restore(); } } @@ -1955,7 +1955,7 @@ || m_dealWasJustSaved || m_toldAboutWonGame || m_toldAboutLostGame - || KMessageBox::warningContinueCancel(0, + || KMessageBox::warningContinueCancel(nullptr, i18n("A new game has been requested, but there is already a game in progress.\n\n" "A loss will be recorded in the statistics if the current game is abandoned."), i18n("Abandon Current Game?"), diff --git a/dealerinfo.h b/dealerinfo.h --- a/dealerinfo.h +++ b/dealerinfo.h @@ -40,7 +40,6 @@ class DealerInfoList; class DealerScene; -class Solver; #include #include diff --git a/freecell.cpp b/freecell.cpp --- a/freecell.cpp +++ b/freecell.cpp @@ -46,9 +46,6 @@ #include -const int CHUNKSIZE = 100; - - Freecell::Freecell( const DealerInfo * di ) : DealerScene( di ) { diff --git a/gameselectionscene.cpp b/gameselectionscene.cpp --- a/gameselectionscene.cpp +++ b/gameselectionscene.cpp @@ -146,7 +146,7 @@ update(); } - void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) Q_DECL_OVERRIDE + void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) Q_DECL_OVERRIDE { Q_UNUSED( option ) Q_UNUSED( widget ) diff --git a/gamestate.h b/gamestate.h --- a/gamestate.h +++ b/gamestate.h @@ -55,7 +55,7 @@ bool takenDown; CardState() - : pile( 0 ), + : pile( nullptr ), index( -1 ), faceUp( false ), takenDown( false ) diff --git a/hint.h b/hint.h --- a/hint.h +++ b/hint.h @@ -47,8 +47,8 @@ { public: MoveHint() - : m_card( 0 ), - m_to( 0 ), + : m_card( nullptr ), + m_to( nullptr ), m_priority( 0 ) { } diff --git a/idiot.cpp b/idiot.cpp --- a/idiot.cpp +++ b/idiot.cpp @@ -171,7 +171,7 @@ && card->pile() != talon && card->pile() != m_away ) { - KCardPile * destination = 0; + KCardPile * destination = nullptr; if ( canMoveAway( card ) ) destination = m_away; else if ( m_play[0]->isEmpty() ) diff --git a/klondike.h b/klondike.h --- a/klondike.h +++ b/klondike.h @@ -74,16 +74,14 @@ void setEasy( bool easy ); bool easyRules; - bool redealt; KSelectAction *options; PatPile* talon; PatPile* play[7]; PatPile* target[4]; KlondikePile *pile; - KCardDeck::Rank target_tops[4]; friend class KlondikeSolver; }; diff --git a/klondike.cpp b/klondike.cpp --- a/klondike.cpp +++ b/klondike.cpp @@ -138,7 +138,6 @@ setActions(DealerScene::Hint | DealerScene::Demo | DealerScene::Draw); setSolver( new KlondikeSolver( this, pile->cardsToShow() ) ); - redealt = false; options = new KSelectAction(i18n("Klondike &Options"), this ); options->addAction( i18n("Draw 1" )); @@ -203,7 +202,6 @@ // Move the cards from the pile back to the deck flipCardsToPile( pile->cards(), talon, DURATION_MOVE ); - redealt = true; } else { @@ -224,7 +222,6 @@ void Klondike::restart( const QList & cards ) { - redealt = false; QList cardList = cards; diff --git a/libkcardgame/kabstractcarddeck.h b/libkcardgame/kabstractcarddeck.h --- a/libkcardgame/kabstractcarddeck.h +++ b/libkcardgame/kabstractcarddeck.h @@ -26,15 +26,14 @@ #include class QSize; -class QPainter; class LIBKCARDGAME_EXPORT KAbstractCardDeck : public QObject { Q_OBJECT public: - explicit KAbstractCardDeck( const KCardTheme & theme = KCardTheme(), QObject * parent = 0 ); + explicit KAbstractCardDeck( const KCardTheme & theme = KCardTheme(), QObject * parent = nullptr ); virtual ~KAbstractCardDeck(); void setDeckContents( const QList & ids ); diff --git a/libkcardgame/kabstractcarddeck.cpp b/libkcardgame/kabstractcarddeck.cpp --- a/libkcardgame/kabstractcarddeck.cpp +++ b/libkcardgame/kabstractcarddeck.cpp @@ -37,7 +37,6 @@ namespace { const QString cacheNameTemplate( QStringLiteral("libkcardgame-themes/%1") ); - const QString timeStampKey( QStringLiteral("libkcardgame_timestamp") ); const QString unscaledSizeKey( QStringLiteral("libkcardgame_unscaledsize") ); const QString lastUsedSizeKey( QStringLiteral("libkcardgame_lastusedsize") ); @@ -100,9 +99,9 @@ : QObject( q ), q( q ), animationCheckTimer( new QTimer( this ) ), - cache( 0 ), - svgRenderer( 0 ), - thread( 0 ) + cache( nullptr ), + svgRenderer( nullptr ), + thread( nullptr ) { animationCheckTimer->setSingleShot( true ); @@ -226,7 +225,7 @@ if ( thread && thread->isRunning() ) thread->halt(); delete thread; - thread = 0; + thread = nullptr; } @@ -449,7 +448,7 @@ { QMutexLocker l( &(d->rendererMutex) ); delete d->svgRenderer; - d->svgRenderer = 0; + d->svgRenderer = nullptr; } delete d->cache; diff --git a/libkcardgame/kcard.h b/libkcardgame/kcard.h --- a/libkcardgame/kcard.h +++ b/libkcardgame/kcard.h @@ -39,7 +39,7 @@ enum { Type = QGraphicsItem::UserType + 1 }; int type() const Q_DECL_OVERRIDE; - void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) Q_DECL_OVERRIDE; + void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) Q_DECL_OVERRIDE; quint32 id() const; int rank() const; diff --git a/libkcardgame/kcard.cpp b/libkcardgame/kcard.cpp --- a/libkcardgame/kcard.cpp +++ b/libkcardgame/kcard.cpp @@ -136,9 +136,9 @@ d->highlighted = false; d->highlightValue = d->highlighted ? 1 : 0; - d->pile = 0; + d->pile = nullptr; - d->animation = 0; + d->animation = nullptr; d->fadeAnimation = new QPropertyAnimation( d, "highlightedness", d ); d->fadeAnimation->setDuration( 150 ); @@ -249,7 +249,7 @@ bool KCard::isAnimated() const { - return d->animation != 0; + return d->animation != nullptr; } @@ -301,7 +301,7 @@ return; delete d->animation; - d->animation = 0; + d->animation = nullptr; setZValue( d->destZ ); diff --git a/libkcardgame/kcarddeck.h b/libkcardgame/kcarddeck.h --- a/libkcardgame/kcarddeck.h +++ b/libkcardgame/kcarddeck.h @@ -64,7 +64,7 @@ const QList & suits = standardSuits(), const QList & ranks = standardRanks() ); - explicit KCardDeck( const KCardTheme & theme = KCardTheme(), QObject * parent = 0 ); + explicit KCardDeck( const KCardTheme & theme = KCardTheme(), QObject * parent = nullptr ); virtual ~KCardDeck(); int rankFromId( quint32 id ) const Q_DECL_OVERRIDE; diff --git a/libkcardgame/kcardpile.h b/libkcardgame/kcardpile.h --- a/libkcardgame/kcardpile.h +++ b/libkcardgame/kcardpile.h @@ -42,7 +42,6 @@ class KCardScene; #include "libkcardgame_export.h" -class QPropertyAnimation; #include @@ -58,7 +57,7 @@ int type() const Q_DECL_OVERRIDE; QRectF boundingRect() const Q_DECL_OVERRIDE; - void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0 ) Q_DECL_OVERRIDE; + void paint( QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = nullptr ) Q_DECL_OVERRIDE; QList cards() const; int count() const; diff --git a/libkcardgame/kcardpile.cpp b/libkcardgame/kcardpile.cpp --- a/libkcardgame/kcardpile.cpp +++ b/libkcardgame/kcardpile.cpp @@ -141,7 +141,7 @@ KCardPile::~KCardPile() { foreach ( KCard * c, d->cards ) - c->setPile( 0 ); + c->setPile( nullptr ); KCardScene * cardScene = dynamic_cast( scene() ); if ( cardScene ) @@ -197,15 +197,15 @@ KCard * KCardPile::at( int index ) const { if ( index < 0 || index >= d->cards.size() ) - return 0; + return nullptr; return d->cards.at( index ); } KCard * KCardPile::topCard() const { if ( d->cards.isEmpty() ) - return 0; + return nullptr; return d->cards.last(); } @@ -441,7 +441,7 @@ { Q_ASSERT( d->cards.contains( card ) ); d->cards.removeAll( card ); - card->setPile( 0 ); + card->setPile( nullptr ); } diff --git a/libkcardgame/kcardscene.h b/libkcardgame/kcardscene.h --- a/libkcardgame/kcardscene.h +++ b/libkcardgame/kcardscene.h @@ -41,7 +41,7 @@ class KCard; class KAbstractCardDeck; -class HighlightableItem; + #include "libkcardgame_export.h" class KCardPile; @@ -66,7 +66,7 @@ }; Q_DECLARE_FLAGS(SceneAlignment, SceneAlignmentFlag) - explicit KCardScene( QObject * parent = 0 ); + explicit KCardScene( QObject * parent = nullptr ); ~KCardScene(); void setDeck( KAbstractCardDeck * deck ); diff --git a/libkcardgame/kcardscene.cpp b/libkcardgame/kcardscene.cpp --- a/libkcardgame/kcardscene.cpp +++ b/libkcardgame/kcardscene.cpp @@ -82,9 +82,9 @@ if ( KCardPile * pile = qobject_cast( object ) ) return pile; - Q_ASSERT( object == 0 ); + Q_ASSERT( !object ); - return 0; + return nullptr; } } @@ -148,7 +148,7 @@ targets << p; } - KCardPile * bestTarget = 0; + KCardPile * bestTarget = nullptr; qreal bestArea = 1; foreach ( KCardPile * p, targets ) @@ -409,7 +409,7 @@ : QGraphicsScene( parent ), d( new KCardScenePrivate( this ) ) { - d->deck = 0; + d->deck = nullptr; d->alignment = AlignHCenter | AlignHSpread; d->layoutMargin = 0.15; d->layoutSpacing = 0.15; @@ -1177,12 +1177,12 @@ if ( e->button() == Qt::LeftButton ) { emit pileClicked( pile ); - emit pile->clicked( 0 ); + emit pile->clicked( nullptr ); } else if ( e->button() == Qt::RightButton ) { emit pileRightClicked( pile ); - emit pile->rightClicked( 0 ); + emit pile->rightClicked( nullptr ); } } else @@ -1216,7 +1216,7 @@ { e->accept(); emit pileDoubleClicked( pile ); - emit pile->doubleClicked( 0 ); + emit pile->doubleClicked( nullptr ); } else { diff --git a/libkcardgame/kcardtheme.cpp b/libkcardgame/kcardtheme.cpp --- a/libkcardgame/kcardtheme.cpp +++ b/libkcardgame/kcardtheme.cpp @@ -102,7 +102,7 @@ KCardTheme::KCardTheme() - : d( 0 ) + : d( nullptr ) { } diff --git a/libkcardgame/kcardthemewidget.h b/libkcardgame/kcardthemewidget.h --- a/libkcardgame/kcardthemewidget.h +++ b/libkcardgame/kcardthemewidget.h @@ -29,7 +29,7 @@ class LIBKCARDGAME_EXPORT KCardThemeWidget : public QWidget { public: - explicit KCardThemeWidget( const QSet & requiredFeatures, const QString & previewString, QWidget * parent = 0 ); + explicit KCardThemeWidget( const QSet & requiredFeatures, const QString & previewString, QWidget * parent = nullptr ); virtual ~KCardThemeWidget(); void setCurrentSelection( const QString & dirName ); diff --git a/libkcardgame/kcardthemewidget.cpp b/libkcardgame/kcardthemewidget.cpp --- a/libkcardgame/kcardthemewidget.cpp +++ b/libkcardgame/kcardthemewidget.cpp @@ -115,7 +115,7 @@ CardThemeModel::CardThemeModel( KCardThemeWidgetPrivate * d, QObject * parent ) : QAbstractListModel( parent ), d( d ), - m_thread( 0 ) + m_thread( nullptr ) { qRegisterMetaType(); @@ -190,7 +190,7 @@ if ( m_thread && m_thread->isRunning() ) m_thread->halt(); delete m_thread; - m_thread = 0; + m_thread = nullptr; } diff --git a/libkcardgame/kcardthemewidget_p.h b/libkcardgame/kcardthemewidget_p.h --- a/libkcardgame/kcardthemewidget_p.h +++ b/libkcardgame/kcardthemewidget_p.h @@ -61,7 +61,7 @@ Q_OBJECT public: - explicit CardThemeModel( KCardThemeWidgetPrivate * d, QObject * parent = 0 ); + explicit CardThemeModel( KCardThemeWidgetPrivate * d, QObject * parent = nullptr ); virtual ~CardThemeModel(); void reload(); @@ -85,7 +85,7 @@ class CardThemeDelegate : public QAbstractItemDelegate { public: - explicit CardThemeDelegate( KCardThemeWidgetPrivate * d, QObject * parent = 0 ); + explicit CardThemeDelegate( KCardThemeWidgetPrivate * d, QObject * parent = nullptr ); void paint( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE; QSize sizeHint( const QStyleOptionViewItem & option, const QModelIndex & index ) const Q_DECL_OVERRIDE; diff --git a/main.cpp b/main.cpp --- a/main.cpp +++ b/main.cpp @@ -77,13 +77,13 @@ if ( !d->solver() ) { qCritical() << "There is no solver for" << di->nameForId( wanted_game );; - return 0; + return nullptr; } return d; } } - return 0; + return nullptr; } // A function to remove all nonalphanumeric characters from a string diff --git a/mainwindow.cpp b/mainwindow.cpp --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -95,13 +95,13 @@ MainWindow::MainWindow() - : KXmlGuiWindow( 0 ), - m_view( 0 ), - m_dealer( 0 ), - m_selector( 0 ), - m_cardDeck( 0 ), - m_soundEngine( 0 ), - m_dealDialog( 0 ) + : KXmlGuiWindow( nullptr ), + m_view( nullptr ), + m_dealer( nullptr ), + m_selector( nullptr ), + m_cardDeck( nullptr ), + m_soundEngine( nullptr ), + m_dealDialog( nullptr ) { setObjectName( QStringLiteral( "MainWindow" ) ); // KCrash::setEmergencySaveFunction(::saveGame); @@ -215,7 +215,7 @@ // action, so we must create a new action and copy all the standard // properties over one by one. m_hintAction = new KToggleAction( actionCollection() ); - a = KStandardGameAction::hint( 0, 0, 0 ); + a = KStandardGameAction::hint( nullptr, nullptr, nullptr ); m_hintAction->setText( a->text() ); m_hintAction->setIcon( a->icon() ); actionCollection()->setDefaultShortcut( m_hintAction, a->shortcut() ); @@ -506,8 +506,8 @@ { m_dealer->recordGameStatistics(); delete m_dealer; - m_view->setScene(0); - m_dealer = 0; + m_view->setScene(nullptr); + m_dealer = nullptr; } if ( !m_cardDeck ) @@ -553,8 +553,8 @@ { m_dealer->recordGameStatistics(); delete m_dealer; - m_view->setScene(0); - m_dealer = 0; + m_view->setScene(nullptr); + m_dealer = nullptr; } if (!m_selector) @@ -684,7 +684,7 @@ } else if ( m_soundEngine ) { - disconnect( m_dealer, 0, m_soundEngine, 0 ); + disconnect( m_dealer, nullptr, m_soundEngine, nullptr ); } } } diff --git a/patsolve/clocksolver.cpp b/patsolve/clocksolver.cpp --- a/patsolve/clocksolver.cpp +++ b/patsolve/clocksolver.cpp @@ -115,8 +115,6 @@ int ClockSolver::get_possible_moves(int *a, int *numout) { - int w, o; - card_t card; MOVE *mp; /* Check for moves from W to O. */ @@ -126,14 +124,14 @@ int left_in_play = 0; int n = 0; mp = Possible; - for (w = 0; w < 8; ++w) + for (int w = 0; w < 8; ++w) { left_in_play += Wlen[w]; if (Wlen[w] > 0) { - card = *Wp[w]; - o = SUIT(card); + card_t card = *Wp[w]; + auto o = SUIT(card); for ( int i = 0; i < 12; ++i ) { if ( o != SUIT( W[8][i] ) ) @@ -155,8 +153,6 @@ mp->turn_index = -1; n++; mp++; - //*a = true; - //return n; } } else if ( first_empty < 0 ) first_empty = w; @@ -184,14 +180,14 @@ if ( Wlen[j] == 0 ) { if ( Wlen[i] > 1 && first_empty == j ) - allowed = 1; + allowed = true; } else { card_t below = *Wp[j]; if ( RANK(card) == RANK( below ) - 1 ) { - allowed = 1; + allowed = true; } } diff --git a/patsolve/fortyeightsolver.h b/patsolve/fortyeightsolver.h --- a/patsolve/fortyeightsolver.h +++ b/patsolve/fortyeightsolver.h @@ -27,7 +27,6 @@ { public: explicit FortyeightSolver(const Fortyeight *dealer); - int good_automove(int o, int r); int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; bool isWon() Q_DECL_OVERRIDE; void make_move(MOVE *m) Q_DECL_OVERRIDE; diff --git a/patsolve/fortyeightsolver.cpp b/patsolve/fortyeightsolver.cpp --- a/patsolve/fortyeightsolver.cpp +++ b/patsolve/fortyeightsolver.cpp @@ -626,7 +626,7 @@ { if ( m.from == NUM_DECK || m.to == NUM_DECK ) return MoveHint(); - PatPile *frompile = 0; + PatPile *frompile = nullptr; if ( m.from < 8 ) frompile = deal->stack[m.from]; else diff --git a/patsolve/freecellsolver.cpp b/patsolve/freecellsolver.cpp --- a/patsolve/freecellsolver.cpp +++ b/patsolve/freecellsolver.cpp @@ -450,17 +450,17 @@ { // this is tricky as we need to want to build the "meta moves" - PatPile *frompile = 0; + PatPile *frompile = nullptr; if ( m.from < 8 ) frompile = deal->store[m.from]; else frompile = deal->freecell[m.from-8]; KCard *card = frompile->at( frompile->count() - m.card_index - 1); if ( m.totype == O_Type ) { - PatPile *target = 0; - PatPile *empty = 0; + PatPile *target = nullptr; + PatPile *empty = nullptr; for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { @@ -476,7 +476,7 @@ target = empty; return MoveHint( card, target, m.pri ); } else { - PatPile *target = 0; + PatPile *target = nullptr; if ( m.to < 8 ) target = deal->store[m.to]; else diff --git a/patsolve/golfsolver.h b/patsolve/golfsolver.h --- a/patsolve/golfsolver.h +++ b/patsolve/golfsolver.h @@ -26,7 +26,7 @@ { public: explicit GolfSolver(const Golf *dealer); - int good_automove(int o, int r); + int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; bool isWon() Q_DECL_OVERRIDE; void make_move(MOVE *m) Q_DECL_OVERRIDE; diff --git a/patsolve/grandfsolver.h b/patsolve/grandfsolver.h --- a/patsolve/grandfsolver.h +++ b/patsolve/grandfsolver.h @@ -26,7 +26,7 @@ { public: explicit GrandfSolver(const Grandf *dealer); - int good_automove(int o, int r); + int get_possible_moves(int *a, int *numout) Q_DECL_OVERRIDE; bool isWon() Q_DECL_OVERRIDE; void make_move(MOVE *m) Q_DECL_OVERRIDE; diff --git a/patsolve/grandfsolver.cpp b/patsolve/grandfsolver.cpp --- a/patsolve/grandfsolver.cpp +++ b/patsolve/grandfsolver.cpp @@ -40,11 +40,10 @@ //print_layout(); #endif - int from, to; card_t card = NONE; - from = m->from; - to = m->to; + auto from = m->from; + auto to = m->to; if ( from == offs ) { @@ -456,15 +455,15 @@ if ( m.from == offs ) return MoveHint(); - PatPile *frompile = 0; + PatPile *frompile = nullptr; frompile = deal->store[m.from % 7]; KCard *card = frompile->at( frompile->count() - m.card_index - 1); if ( m.totype == O_Type ) { - PatPile *target = 0; - PatPile *empty = 0; + PatPile *target = nullptr; + PatPile *empty = nullptr; for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { @@ -482,7 +481,6 @@ } else { return MoveHint( card, deal->store[m.to % 7], m.pri ); } - return MoveHint(); } void GrandfSolver::print_layout() diff --git a/patsolve/gypsysolver.cpp b/patsolve/gypsysolver.cpp --- a/patsolve/gypsysolver.cpp +++ b/patsolve/gypsysolver.cpp @@ -538,8 +538,8 @@ if ( m.totype == O_Type ) { - PatPile *target = 0; - PatPile *empty = 0; + PatPile *target = nullptr; + PatPile *empty = nullptr; for (int i = 0; i < 8; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { diff --git a/patsolve/idiotsolver.cpp b/patsolve/idiotsolver.cpp --- a/patsolve/idiotsolver.cpp +++ b/patsolve/idiotsolver.cpp @@ -242,7 +242,7 @@ KCard *card = frompile->at( frompile->count() - m.card_index - 1); Q_ASSERT( card ); - PatPile *target = 0; + PatPile *target = nullptr; if ( m.to == 5 ) target = deal->m_away; else diff --git a/patsolve/klondikesolver.cpp b/patsolve/klondikesolver.cpp --- a/patsolve/klondikesolver.cpp +++ b/patsolve/klondikesolver.cpp @@ -538,7 +538,7 @@ MoveHint KlondikeSolver::translateMove( const MOVE &m ) { - PatPile *frompile = 0; + PatPile *frompile = nullptr; if ( m.from == 8 && m.to == 7 ) return MoveHint(); Q_ASSERT( m.from != 8 ); @@ -551,8 +551,8 @@ if ( m.totype == O_Type ) { - PatPile *target = 0; - PatPile *empty = 0; + PatPile *target = nullptr; + PatPile *empty = nullptr; for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { diff --git a/patsolve/memory.h b/patsolve/memory.h --- a/patsolve/memory.h +++ b/patsolve/memory.h @@ -68,7 +68,7 @@ TREELIST *cluster_tree(unsigned int cluster); inscode insert_node(TREE *n, int d, TREE **tree, TREE **node); void give_back_block(unsigned char *p); - void init_buckets( int i ); + BLOCK *new_block(void); template diff --git a/patsolve/memory.cpp b/patsolve/memory.cpp --- a/patsolve/memory.cpp +++ b/patsolve/memory.cpp @@ -42,27 +42,27 @@ key = (quint8 *)n + sizeof(TREE); n->depth = d; - n->left = n->right = NULL; + n->left = n->right = nullptr; *node = n; t = *tree; - if (t == NULL) { + if (t == nullptr) { *tree = n; return NEW; } - while (1) { + while (true) { tkey = (quint8 *)t + sizeof(TREE); c = memcmp(key, tkey, Pilebytes); if (c == 0) { break; } if (c < 0) { - if (t->left == NULL) { + if (t->left == nullptr) { t->left = n; return NEW; } t = t->left; } else { - if (t->right == NULL) { + if (t->right == nullptr) { t->right = n; return NEW; } @@ -104,7 +104,7 @@ /* Find the tree in this bucket with that cluster number. */ - last = NULL; + last = nullptr; for (tl = Treelist[bucket]; tl; tl = tl->next) { if (tl->cluster == cluster) { break; @@ -114,15 +114,15 @@ /* If we didn't find it, make a new one and add it to the list. */ - if (tl == NULL) { + if (tl == nullptr) { tl = mm_allocate(TREELIST); - if (tl == NULL) { - return NULL; + if (tl == nullptr) { + return nullptr; } - tl->tree = NULL; + tl->tree = nullptr; tl->cluster = cluster; - tl->next = NULL; - if (last == NULL) { + tl->next = nullptr; + if (last == nullptr) { Treelist[bucket] = tl; } else { last->next = tl; @@ -139,17 +139,17 @@ BLOCK *b; b = mm_allocate(BLOCK); - if (b == NULL) { - return NULL; + if (b == nullptr) { + return nullptr; } b->block = new_array(quint8, BLOCKSIZE); - if (b->block == NULL) { + if (b->block == nullptr) { MemoryManager::free_ptr(b); - return NULL; + return nullptr; } b->ptr = b->block; b->remain = BLOCKSIZE; - b->next = NULL; + b->next = nullptr; return b; } @@ -164,8 +164,8 @@ b = Block; if (s > b->remain) { b = new_block(); - if (b == NULL) { - return NULL; + if (b == nullptr) { + return nullptr; } b->next = Block; Block = b; @@ -228,14 +228,14 @@ void *x; if (s > Mem_remain) { - return NULL; + return nullptr; } - if ((x = (void *)malloc(s)) == NULL) { - return NULL; + // use calloc to ensure that the memory is zeroed + if ((x = calloc(1, s)) == nullptr) { + return nullptr; } - memset( x, 0, s ); Mem_remain -= s; return x; } diff --git a/patsolve/patsolve.h b/patsolve/patsolve.h --- a/patsolve/patsolve.h +++ b/patsolve/patsolve.h @@ -53,16 +53,13 @@ } }; -struct POSITION; - struct POSITION { POSITION *queue; /* next position in the queue */ POSITION *parent; /* point back up the move stack */ TREE *node; /* compact position rep.'s tree node */ MOVE move; /* move that got us here from the parent */ quint32 cluster; /* the cluster this node is in */ short depth; /* number of moves so far */ - quint8 ntemp; /* number of cards in T */ quint8 nchild; /* number of child nodes left */ }; @@ -83,7 +80,7 @@ Solver(); virtual ~Solver(); ExitStatus patsolve( int max_positions = -1, bool debug = false); - bool recursive(POSITION *pos = 0); + bool recursive(POSITION *pos = nullptr); virtual void translate_layout() = 0; bool m_shouldEnd; QMutex endMutex; @@ -99,8 +96,7 @@ virtual int get_possible_moves(int *a, int *numout) = 0; int translateSuit( int s ); - int wcmp(int a, int b); - void queue_position(POSITION *pos, int pri); + void queue_position(POSITION *pos, int pri); void free_position(POSITION *pos, int); POSITION *dequeue_position(); void hashpile(int w); @@ -156,7 +152,6 @@ POSITION *Qhead[NQUEUES]; /* separate queue for each priority */ int Maxq; - bool m_newer_piles_first; unsigned long Total_generated, Total_positions; qreal depth_sum; diff --git a/patsolve/patsolve.cpp b/patsolve/patsolve.cpp --- a/patsolve/patsolve.cpp +++ b/patsolve/patsolve.cpp @@ -95,7 +95,7 @@ { int i, alln, a, numout = 0; - if ( parent == NULL ) { + if ( parent == nullptr ) { init(); recu_pos.clear(); delete Stack; @@ -135,7 +135,7 @@ return false; MOVE *mp0 = new_array(MOVE, alln+1); - if (mp0 == NULL) { + if (mp0 == nullptr) { return false; } MOVE *mp = mp0; @@ -152,7 +152,7 @@ for (mp = mp0; mp->card_index != -1; ++mp) { int depth = 0; - if (parent != NULL) + if (parent != nullptr) depth = parent->depth + 1; make_move(mp); @@ -164,7 +164,7 @@ Total_generated++; POSITION *pos = &Stack[depth]; - pos->queue = NULL; + pos->queue = nullptr; pos->parent = parent; pos->node = pack_position(); quint8 *key = (quint8 *)pos->node + sizeof(TREE); @@ -183,7 +183,7 @@ quint8 *tkey = (quint8 *)Stack[i].node + sizeof(TREE); if ( !memcmp( key, tkey, mm->Pilebytes ) ) { - key = 0; + key = nullptr; break; } } @@ -214,10 +214,10 @@ MemoryManager::free_array(mp0, alln); - if ( parent == NULL ) { + if ( parent == nullptr ) { printf( "Total %ld\n", Total_generated ); delete [] Stack; - Stack = 0; + Stack = nullptr; } return fit; } @@ -254,7 +254,7 @@ if (n == 0) { /* No more moves - won or lost */ //print_layout(); - return NULL; + return nullptr; } /* Prioritize these moves. Automoves don't get queued, so they @@ -271,8 +271,8 @@ moves. */ mp = mp0 = new_array(MOVE, n); - if (mp == NULL) { - return NULL; + if (mp == nullptr) { + return nullptr; } *nmoves = n; i = 0; @@ -306,17 +306,6 @@ int Posbytes; -/* Comparison function for sorting the W piles. */ - -int Solver::wcmp(int a, int b) -{ - if (m_newer_piles_first) { - return Wpilenum[b] - Wpilenum[a]; /* newer piles first */ - } else { - return Wpilenum[a] - Wpilenum[b]; /* older piles first */ - } -} - void Solver::pilesort(void) { /* Make sure all the piles have id numbers. */ @@ -370,9 +359,9 @@ will get filled in later, by insert_node(). */ p = mm->new_from_block(Treebytes); - if (p == NULL) { + if (p == nullptr) { Status = UnableToDetermineSolvability; - return NULL; + return nullptr; } node = (TREE *)p; p += sizeof(TREE); @@ -391,7 +380,7 @@ if ( j < 0 ) { mm->give_back_block( p ); - return NULL; + return nullptr; } *p2++ = j; } @@ -419,7 +408,6 @@ void Solver::unpack_position(POSITION *pos) { int i, w; - quint8 c; BUCKETLIST *l; unpack_cluster(pos->cluster); @@ -432,7 +420,7 @@ j j */ - w = i = c = 0; + w = i = 0; quint16 *p2 = ( quint16* )( (quint8 *)(pos->node) + sizeof(TREE) ); while (w < m_number_piles) { i = *p2++; @@ -481,7 +469,7 @@ //printf("Winning in %d moves.\n", nmoves); mpp0 = new_array(MOVE *, nmoves); - if (mpp0 == NULL) { + if (mpp0 == nullptr) { Status = UnableToDetermineSolvability; return; /* how sad, so close... */ } @@ -551,7 +539,7 @@ /* Look for the pile in this bucket. */ - last = NULL; + last = nullptr; for (l = Bucketlist[bucket]; l; l = l->next) { if (l->hash == Whash[w] && strncmp((char*)l->pile, (char*)W[w], Wlen[w]) == 0) { @@ -562,20 +550,20 @@ /* If we didn't find it, make a new one and add it to the list. */ - if (l == NULL) { + if (l == nullptr) { if (Pilenum >= NPILES ) { Status = UnableToDetermineSolvability; //qDebug() << "out of piles"; return -1; } l = mm_allocate(BUCKETLIST); - if (l == NULL) { + if (l == nullptr) { Status = UnableToDetermineSolvability; //qDebug() << "out of buckets"; return -1; } l->pile = new_array(quint8, Wlen[w] + 1); - if (l->pile == NULL) { + if (l->pile == nullptr) { Status = UnableToDetermineSolvability; MemoryManager::free_ptr(l); //qDebug() << "out of memory"; @@ -588,8 +576,8 @@ strncpy((char*)l->pile, (char*)W[w], Wlen[w] + 1); l->hash = Whash[w]; l->pilenum = pilenum = Pilenum++; - l->next = NULL; - if (last == NULL) { + l->next = nullptr; + if (last == nullptr) { Bucketlist[bucket] = l; } else { last->next = l; @@ -642,7 +630,7 @@ /* Init the queues. */ for (i = 0; i < NQUEUES; ++i) { - Qhead[i] = NULL; + Qhead[i] = nullptr; } Maxq = 0; @@ -652,17 +640,17 @@ pilesort(); m.card_index = -1; m.turn_index = -1; - pos = new_position(NULL, &m); - if ( pos == NULL ) + pos = new_position(nullptr, &m); + if ( pos == nullptr ) { Status = UnableToDetermineSolvability; return; } queue_position(pos, 0); /* Solve it. */ - while ((pos = dequeue_position()) != NULL) { + while ((pos = dequeue_position()) != nullptr) { q = solve(pos); if (!q) { free_position(pos, true); @@ -709,7 +697,7 @@ /* Generate an array of all the moves we can make. */ - if ((mp0 = get_moves(&nmoves)) == NULL) { + if ((mp0 = get_moves(&nmoves)) == nullptr) { if ( isWon() ) { Status = SolutionExists; win( parent ); @@ -738,7 +726,7 @@ /* See if this is a new position. */ - if ((pos = new_position(parent, mp)) == NULL) { + if ((pos = new_position(parent, mp)) == nullptr) { undo_move(mp); parent->nchild--; continue; @@ -790,7 +778,7 @@ pos->queue = Freepos; Freepos = pos; pos = pos->parent; - if (pos == NULL) { + if (pos == nullptr) { return; } pos->nchild--; @@ -827,8 +815,8 @@ at the head or tail of the queue, depending on whether we're pretending it's a stack or a queue. */ - pos->queue = NULL; - if (Qhead[pri] == NULL) { + pos->queue = nullptr; + if (Qhead[pri] == nullptr) { Qhead[pri] = pos; } else { pos->queue = Qhead[pri]; @@ -857,7 +845,7 @@ qpos--; if (qpos < minpos) { if (last) { - return NULL; + return nullptr; } qpos = Maxq; minpos--; @@ -868,14 +856,14 @@ last = true; } } - } while (Qhead[qpos] == NULL); + } while (Qhead[qpos] == nullptr); pos = Qhead[qpos]; Qhead[qpos] = pos->queue; /* Decrease Maxq if that queue emptied. */ - while (Qhead[qpos] == NULL && qpos == Maxq && Maxq > 0) { + while (Qhead[qpos] == nullptr && qpos == Maxq && Maxq > 0) { Maxq--; qpos--; if (qpos < minpos) { @@ -893,17 +881,16 @@ Solver::Solver() { mm = new MemoryManager(); - Freepos = NULL; - m_newer_piles_first = true; + Freepos = nullptr; /* Work arrays. */ - W = 0; - Wp = 0; + W = nullptr; + Wp = nullptr; - Wlen = 0; + Wlen = nullptr; - Whash = 0; - Wpilenum = 0; - Stack = 0; + Whash = nullptr; + Wpilenum = nullptr; + Stack = nullptr; } Solver::~Solver() @@ -944,7 +931,7 @@ free_buckets(); mm->free_clusters(); mm->free_blocks(); - Freepos = NULL; + Freepos = nullptr; } @@ -1036,14 +1023,14 @@ /* Get the tree for this cluster. */ TREELIST *tl = mm->cluster_tree(k); - if (tl == NULL) { + if (tl == nullptr) { return MemoryManager::ERR; } /* Create a compact position representation. */ TREE *newtree = pack_position(); - if (newtree == NULL) { + if (newtree == nullptr) { return MemoryManager::ERR; } Total_generated++; @@ -1068,7 +1055,7 @@ /* Search the list of stored positions. If this position is found, then ignore it and return (unless this position is better). */ - if (parent == NULL) { + if (parent == nullptr) { depth = 0; } else { depth = parent->depth + 1; @@ -1078,7 +1065,7 @@ Total_positions++; depth_sum += depth; } else - return NULL; + return nullptr; /* A new or better position. insert() already stashed it in the @@ -1090,14 +1077,14 @@ Freepos = Freepos->queue; } else { p = mm->new_from_block(Posbytes); - if (p == NULL) { + if (p == nullptr) { Status = UnableToDetermineSolvability; - return NULL; + return nullptr; } } pos = (POSITION *)p; - pos->queue = NULL; + pos->queue = nullptr; pos->parent = parent; pos->node = node; pos->move = *m; /* struct copy */ diff --git a/patsolve/spidersolver.cpp b/patsolve/spidersolver.cpp --- a/patsolve/spidersolver.cpp +++ b/patsolve/spidersolver.cpp @@ -385,14 +385,13 @@ else { if ( conti[j]+l+1 != 13 || conti[i]>conti[j]+l ) { - card_t card_below; + card_t card_below {}; bool exists_card_below = Wlen[i] >= l + 2; if (exists_card_below) { card_below = W[i][Wlen[i]-l-2]; } - if ( !exists_card_below || ( exists_card_below && - ( SUIT( card_below ) != SUIT( card ) || - RANK(card_below) != RANK(card) + 1 ) + if ( !exists_card_below || ((SUIT(card_below ) != SUIT(card ) || + RANK(card_below) != RANK(card) + 1) ) ) { @@ -611,7 +610,6 @@ if ( m.totype == O_Type ) { return MoveHint(); // the move to the legs is fully automated - return MoveHint( frompile->topCard(), deal->legs[0], m.pri ); // for now } Q_ASSERT( m.from < 10 && m.to < 10 ); diff --git a/patsolve/yukonsolver.cpp b/patsolve/yukonsolver.cpp --- a/patsolve/yukonsolver.cpp +++ b/patsolve/yukonsolver.cpp @@ -392,15 +392,15 @@ MoveHint YukonSolver::translateMove( const MOVE &m ) { - PatPile *frompile = 0; + PatPile *frompile = nullptr; frompile = deal->store[m.from]; KCard *card = frompile->at( frompile->count() - m.card_index - 1); if ( m.totype == O_Type ) { - PatPile *target = 0; - PatPile *empty = 0; + PatPile *target = nullptr; + PatPile *empty = nullptr; for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { diff --git a/renderer.h b/renderer.h --- a/renderer.h +++ b/renderer.h @@ -21,10 +21,8 @@ #include -class QSize; class QString; class QColor; -class QPixmap; class Renderer : public KGameRenderer diff --git a/renderer.cpp b/renderer.cpp --- a/renderer.cpp +++ b/renderer.cpp @@ -23,21 +23,21 @@ #include -Renderer * Renderer::s_instance = 0; +Renderer * Renderer::s_instance = nullptr; Renderer * Renderer::self() { - if ( s_instance == 0 ) + if ( s_instance == nullptr ) s_instance = new Renderer(); return s_instance; } void Renderer::deleteSelf() { delete s_instance; - s_instance = 0; + s_instance = nullptr; } diff --git a/soundengine.h b/soundengine.h --- a/soundengine.h +++ b/soundengine.h @@ -26,7 +26,7 @@ Q_OBJECT public: - explicit SoundEngine( QObject * parent = 0 ); + explicit SoundEngine( QObject * parent = nullptr ); virtual ~SoundEngine(); public slots: