コード例 #1
0
ファイル: gypsysolver.cpp プロジェクト: jsj2008/kdegames
MoveHint GypsySolver::translateMove( const MOVE &m )
{
    //print_layout();
    if ( m.from == deck )
        return MoveHint();

    PatPile *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;
        for (int i = 0; i < 8; ++i) {
            KCard *c = deal->target[i]->topCard();
            if (c) {
                if ( c->suit() == card->suit() && c->rank() == card->rank() - 1)
                {
                    target = deal->target[i];
                    break;
                }
            } else if ( !empty )
                empty = deal->target[i];
        }
        if ( !target )
            target = empty;
        return MoveHint( card, target, m.pri );
    }

    return MoveHint( card, deal->store[m.to], m.pri );
}
コード例 #2
0
ファイル: golfsolver.cpp プロジェクト: jsj2008/kdegames
MoveHint GolfSolver::translateMove( const MOVE &m )
{
    if ( m.from >= 7 )
        return MoveHint();
    PatPile *frompile = deal->stack[m.from];

    KCard *card = frompile->at( frompile->count() - m.card_index - 1);

    return MoveHint( card, deal->waste, m.pri );
}
コード例 #3
0
ファイル: clocksolver.cpp プロジェクト: shlomif/kpat
MoveHint ClockSolver::translateMove( const MOVE &m )
{
    PatPile *frompile = deal->store[m.from];
    KCard *card = frompile->topCard();

    if ( m.totype == O_Type )
    {
        return MoveHint( card, deal->target[m.to], m.pri );
    } else {
        return MoveHint( card, deal->store[m.to], m.pri );
    }
}
コード例 #4
0
ファイル: mod3solver.cpp プロジェクト: jsj2008/kdegames
MoveHint Mod3Solver::translateMove( const MOVE & m )
{
    if ( m.from == deck )
        return MoveHint();

    PatPile *frompile = deal->stack[m.from / 8][m.from % 8];
    KCard *card = frompile->topCard();

    if ( m.to == aces )
    {
        return MoveHint( card, deal->aces, m.pri );
    } else {
        return MoveHint( card, deal->stack[m.to / 8][m.to % 8], m.pri );
    }
}
コード例 #5
0
ファイル: spider.cpp プロジェクト: KDE/kpat
void Spider::cardsMoved( const QList<KCard*> & cards, KCardPile * oldPile, KCardPile * newPile )
{
    PatPile * p = dynamic_cast<PatPile*>( newPile );

    // The solver treats the removal of complete runs from the table as a
    // separate move, so we don't do it automatically when the demo is active.
    if ( !isDemoActive()
         && p
         && p->pileRole() == PatPile::Tableau
         && pileHasFullRun( p ) )
    {
        m_pilesWithRuns << p;
    }

    DealerScene::cardsMoved( cards, oldPile, newPile );
}
コード例 #6
0
ファイル: simonsolver.cpp プロジェクト: KDE/kpat
MoveHint SimonSolver::translateMove( const MOVE &m )
{
    Q_ASSERT( m.from < 10 && m.to < 10 );

    PatPile *frompile = deal->store[m.from];
    KCard *card = frompile->at( frompile->count() - m.card_index - 1);

    if ( m.totype == O_Type )
    {
        for ( int i = 0; i < 4; ++i )
            if ( deal->target[i]->isEmpty() )
                return MoveHint( card, deal->target[i], 127 );
    }

    Q_ASSERT( m.to < 10 );
    return MoveHint( card, deal->store[m.to], m.pri );
}
コード例 #7
0
ファイル: idiotsolver.cpp プロジェクト: shlomif/kpat
MoveHint IdiotSolver::translateMove( const MOVE &m )
{
    if ( m.from >=4 )
        return MoveHint();
    PatPile *frompile = deal->m_play[m.from];

    KCard *card = frompile->at( frompile->count() - m.card_index - 1);
    Q_ASSERT( card );

    PatPile *target = nullptr;
    if ( m.to == 5 )
        target = deal->m_away;
    else
        target = deal->m_play[m.to];

    return MoveHint( card, target, m.pri );
}
コード例 #8
0
ファイル: klondikesolver.cpp プロジェクト: KDE/kpat
MoveHint KlondikeSolver::translateMove( const MOVE &m )
{
    PatPile *frompile = 0;
    if ( m.from == 8 && m.to == 7 )
        return MoveHint();
    Q_ASSERT( m.from != 8 );
    if ( m.from == 7 )
        frompile = deal->pile;
    else
        frompile = deal->play[m.from];

    KCard *card = frompile->at( frompile->count() - m.card_index - 1);

    if ( m.totype == O_Type )
    {
        PatPile *target = 0;
        PatPile *empty = 0;
        for (int i = 0; i < 4; ++i) {
            KCard *c = deal->target[i]->topCard();
            if (c) {
                if ( c->suit() == card->suit() )
                {
                    target = deal->target[i];
                    break;
                }
            } else if ( !empty )
                empty = deal->target[i];
        }
        if ( !target )
            target = empty;
        return MoveHint( card, target, m.pri );
    } else {
        if ( m.to == 7 )
        {
            return MoveHint( card, deal->pile, m.pri );
        } else if ( m.to == 8 )
            return MoveHint();
        else
            return MoveHint( card, deal->play[m.to], m.pri );
    }
}
コード例 #9
0
ファイル: freecellsolver.cpp プロジェクト: KDE/kpat
MoveHint FreecellSolver::translateMove( const MOVE &m )
{
    // this is tricky as we need to want to build the "meta moves"

    PatPile *frompile = 0;
    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;
        for (int i = 0; i < 4; ++i) {
            KCard *c = deal->target[i]->topCard();
            if (c) {
                if ( c->suit() == card->suit() )
                {
                    target = deal->target[i];
                    break;
                }
            } else if ( !empty )
                empty = deal->target[i];
        }
        if ( !target )
            target = empty;
        return MoveHint( card, target, m.pri );
    } else {
        PatPile *target = 0;
        if ( m.to < 8 )
            target = deal->store[m.to];
        else
            target = deal->freecell[m.to-8];

        return MoveHint( card, target, m.pri );
    }
}
コード例 #10
0
ファイル: spider.cpp プロジェクト: KDE/kpat
void Spider::moveFullRunToLeg( KCardPile * pile )
{
    QList<KCard*> run = pile->topCards( 13 );

    PatPile * leg = legs[m_leg];
    ++m_leg;
    leg->setVisible( true );

    recalculatePileLayouts();
    for ( int i = 0; i < 10; ++i )
        if ( stack[i] != pile )
            updatePileLayout( stack[i], DURATION_RELAYOUT );

    for ( int i = 0; i < run.size(); ++i )
    {
        KCard * c = run.at( i );
        leg->add( c );
        int duration = DURATION_AUTODROP * (0.7 + i / 10.0);
        c->animate( leg->pos(), leg->zValue() + i, 0, true, true, duration );
    }

    updatePileLayout( pile, DURATION_RELAYOUT );
}