Ejemplo n.º 1
0
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 );
}
Ejemplo n.º 2
0
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 );
}
Ejemplo n.º 3
0
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 );
}
Ejemplo n.º 4
0
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 );
}
Ejemplo n.º 5
0
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 );
    }
}
Ejemplo n.º 6
0
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 );
    }
}