1
/* Common routines & arrays. */
13
#include <sys/types.h>
21
void GolfSolver::make_move(MOVE *m)
24
if ( m->totype == O_Type )
25
fprintf( stderr, "\nmake move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index );
27
fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index );
37
Q_ASSERT( from != 7 );
40
if ( from == 8 && to == 7 )
45
card = ( SUIT( card ) << 4 ) + RANK( card );
57
card_t card = *Wp[from];
72
void GolfSolver::undo_move(MOVE *m)
75
if ( m->totype == O_Type )
76
fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index );
78
fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index );
87
Q_ASSERT( from != 7 );
90
if ( from == 8 && to == 7 )
95
card = ( SUIT( card ) << 4 ) + RANK( card ) + ( 1 << 7 );
107
card_t card = *Wp[to];
122
/* Get the possible moves from a position, and store them in Possible[]. */
124
int GolfSolver::get_possible_moves(int *a, int *numout)
133
for (int w = 0; w < 7; w++) {
135
card_t card = *Wp[w];
136
if (RANK(card) == RANK(top) - 1 ||
137
RANK(card) == RANK(top) + 1 )
144
if ( RANK( card ) == PS_ACE || RANK( card ) == PS_KING )
153
/* check for deck->pile */
154
if ( !n && Wlen[8] ) {
168
void GolfSolver::unpack_cluster( int )
172
bool GolfSolver::isWon()
174
//kDebug() << "isWon" << Wlen[7];
175
return Wlen[7] == 52 ;
178
int GolfSolver::getOuts()
183
GolfSolver::GolfSolver(const Golf *dealer)
190
/* Read a layout file. Format is one pile per line, bottom to top (visible
191
card). Temp cells and Out on the last two lines, if any. */
193
void GolfSolver::translate_layout()
195
/* Read the workspace. */
198
for ( int w = 0; w < 7; ++w ) {
199
int i = translate_pile(deal->stack[w], W[w], 52);
200
Wp[w] = &W[w][i - 1];
205
int i = translate_pile( deal->waste, W[7], 52 );
210
i = translate_pile( Deck::deck(), W[8], 52 );
215
for ( int i = 0; i < 9; i++ )
217
for ( int l = 0; l < Wlen[i]; l++ )
219
card_t card = W[i][l];
221
card = RANK( card ) + PS_SPADE + ( 1 << 7 );
223
card = RANK( card ) + PS_SPADE;
229
int GolfSolver::getClusterNumber()
234
MoveHint *GolfSolver::translateMove( const MOVE &m )
238
Pile *frompile = deal->stack[m.from];
240
Card *card = frompile->at( frompile->cardsLeft() - m.card_index - 1);
242
return new MoveHint( card, deal->waste, m.pri );
245
void GolfSolver::print_layout()
247
fprintf(stderr, "print-layout-begin\n");
248
for (int w = 0; w < 9; w++) {
250
fprintf( stderr, "Deck: " );
252
fprintf( stderr, "Pile: " );
254
fprintf( stderr, "Play%d: ", w );
255
for (int i = 0; i < Wlen[w]; i++) {
256
printcard(W[w][i], stderr);
260
fprintf(stderr, "print-layout-end\n");