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 ); }
void ClockSolver::translate_layout() { /* Read the workspace. */ int total = 0; for ( int w = 0; w < 8; ++w ) { int i = translate_pile(deal->store[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; total += i; } /* Output piles, if any. */ for (int i = 0; i < 12; ++i) { KCard *c = deal->target[i]->topCard(); // It is not safe to assume that each target pile will always have a // card on it. If it takes particularly long to render the card graphics // at the start of a new game, it is possible that this method can be // called before the initial deal has been completed. if (c) W[8][i] = translateSuit( c->suit() ) + c->rank(); } Wp[8] = &W[8][11]; Wlen[8] = 12; }
void YukonSolver::translate_layout() { /* Read the workspace. */ int total = 0; for ( int w = 0; w < 7; ++w ) { int i = translate_pile(deal->store[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; total += i; } /* Output piles, if any. */ for (int i = 0; i < 4; ++i) { O[i] = NONE; } if (total != 52) { for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { O[translateSuit( c->suit() ) >> 4] = c->rank(); total += c->rank(); } } } Q_ASSERT( total == 52 ); }
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 ); } }
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 ); } }
void SimonSolver::translate_layout() { /* Read the workspace. */ int total = 0; for ( int w = 0; w < 10; ++w ) { int i = translate_pile(deal->store[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; total += i; } for (int i = 0; i < 4; ++i) { O[i] = -1; KCard *c = deal->target[i]->topCard(); if (c) { total += 13; O[i] = translateSuit( c->suit() ); } } }
bool Fortyeight::canPutStore( const KCardPile * pile, const QList<KCard*> &cards ) const { int frees = 0; for (int i = 0; i < 8; i++) if (stack[i]->isEmpty()) frees++; if ( pile->isEmpty()) // destination is empty frees--; if (int( cards.count()) > 1<<frees) return false; // ok if the target is empty if ( pile->isEmpty()) return true; KCard *c = cards.first(); // we assume there are only valid sequences return pile->topCard()->suit() == c->suit() && pile->topCard()->rank() == c->rank() + 1; }
void FreecellSolver::translate_layout() { /* Read the workspace. */ int total = 0; for ( int w = 0; w < 8; ++w ) { int i = translate_pile(deal->store[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; total += i; if (w == Nwpiles) { break; } } /* Temp cells may have some cards too. */ for (int w = 0; w < Ntpiles; ++w) { int i = translate_pile( deal->freecell[w], W[w+Nwpiles], 52 ); Wp[w+Nwpiles] = &W[w+Nwpiles][i-1]; Wlen[w+Nwpiles] = i; total += i; } /* Output piles, if any. */ for (int i = 0; i < 4; ++i) { O[i] = NONE; } if (total != 52) { for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { O[translateSuit( c->suit() ) >> 4] = c->rank(); total += c->rank(); } } } }
void KlondikeSolver::translate_layout() { /* Read the workspace. */ int total = 0; for ( int w = 0; w < 7; ++w ) { int i = translate_pile(deal->play[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; total += i; } int i = translate_pile( deal->pile, W[7], 52 ); Wp[7] = &W[7][i-1]; Wlen[7] = i; total += i; i = translate_pile( deal->talon, W[8], 52 ); Wp[8] = &W[8][i-1]; Wlen[8] = i; total += i; /* Output piles, if any. */ for (int i = 0; i < 4; ++i) { O[i] = NONE; } if (total != 52) { for (int i = 0; i < 4; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { O[translateSuit( c->suit() ) >> 4] = c->rank(); total += c->rank(); } } } }
void GypsySolver::translate_layout() { /* Read the workspace. */ for ( int w = 0; w < 8; ++w ) { int i = translate_pile(deal->store[w], W[w], 52); Wp[w] = &W[w][i - 1]; Wlen[w] = i; } deck = 8; int i = translate_pile( deal->talon, W[deck], 80 ); Wp[deck] = &W[deck][i-1]; Wlen[deck] = i; outs = 9; /* Output piles, if any. */ for (int i = 0; i < 8; ++i) { Wlen[outs + i] = 0; Wp[outs + i] = &W[outs + i][-1]; } for (int i = 0; i < 8; ++i) { KCard *c = deal->target[i]->topCard(); if (c) { int suit = translateSuit( c->suit() ) >> 4; int target = outs + suit*2; if ( Wlen[target] ) target++; Wp[target]++; Wlen[target]++; *Wp[target] = ( suit << 4 ) + c->rank(); } } }