void YukonSolver::undo_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; /* Add to 'from' pile. */ if ( m->turn_index > 0 ) { card_t card2 = *Wp[from]; if ( !DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ) + ( 1 << 7 ); *Wp[from] = card2; } if (m->totype == O_Type) { card = O[to] + Osuit[to]; O[to]--; Wp[from]++; *Wp[from] = card; Wlen[from]++; } else { for ( int l = m->card_index; l >= 0; l-- ) { card = W[to][Wlen[to]-l-1]; Wp[from]++; *Wp[from] = card; Wlen[from]++; *Wp[to]--; } Wlen[to] -= m->card_index + 1; hashpile(to); } if ( m->turn_index == 0 ) { card_t card = *Wp[from]; if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); *Wp[from] = card; } hashpile(from); #if PRINT print_layout(); #endif }
void YukonSolver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from, to; card_t card = NONE; from = m->from; to = m->to; for ( int l = m->card_index; l >= 0; l-- ) { card = W[from][Wlen[from]-l-1]; Wp[from]--; if ( m->totype != O_Type ) { Wp[to]++; *Wp[to] = card; Wlen[to]++; } } Wlen[from] -= m->card_index + 1; if ( m->turn_index == 0 ) { if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); W[to][Wlen[to]-m->card_index-1] = card; } else if ( m->turn_index != -1 ) { card_t card2 = *Wp[from]; if ( DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ); *Wp[from] = card2; } hashpile(from); /* Add to pile. */ if (m->totype == O_Type) { O[to]++; Q_ASSERT( m->card_index == 0 ); } else { hashpile(to); } #if PRINT print_layout(); #endif }
void SimonSolver::undo_move(MOVE *m) { #if PRINT //qDebug() << "\n\nundo_move\n"; if ( m->totype == O_Type ) fprintf( stderr, "move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; if (m->totype == O_Type) { for ( int j = PS_KING; j >= PS_ACE; --j ) { Wp[from]++; *Wp[from] = O[to] + j; Wlen[from]++; } O[to] = -1; hashpile( from ); #if PRINT print_layout(); #endif return; } /* Add to 'from' pile. */ if ( m->turn_index > 0 ) { card_t card2 = *Wp[from]; if ( !DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ) + ( 1 << 7 ); *Wp[from] = card2; } for ( int l = m->card_index; l >= 0; --l ) { card = W[to][Wlen[to]-l-1]; Wp[from]++; *Wp[from] = card; Wlen[from]++; Wp[to]--; } Wlen[to] -= m->card_index + 1; hashpile(to); hashpile(from); #if PRINT print_layout(); #endif }
void SimonSolver::make_move(MOVE *m) { #if PRINT //qDebug() << "\n\nmake_move\n"; if ( m->totype == O_Type ) fprintf( stderr, "move %d from %d out (at %d) Prio: %d\n\n", m->card_index, m->from, m->turn_index, m->pri ); else fprintf( stderr, "move %d from %d to %d (%d) Prio: %d\n\n", m->card_index, m->from, m->to, m->turn_index, m->pri ); print_layout(); #else //print_layout(); #endif int from, to; card_t card = NONE; from = m->from; to = m->to; if (m->totype == O_Type) { O[to] = SUIT( *Wp[from] ); Wlen[from] -= 13; Wp[from] -= 13; hashpile( from ); if ( Wlen[from] && DOWN( *Wp[from] ) ) { *Wp[from] = ( SUIT( *Wp[from] ) << 4 ) + RANK( *Wp[from] ); } #if PRINT print_layout(); #endif return; } for ( int l = m->card_index; l >= 0; --l ) { card = W[from][Wlen[from]-l-1]; Wp[from]--; if ( m->totype != O_Type ) { Wp[to]++; *Wp[to] = card; Wlen[to]++; } } Wlen[from] -= m->card_index + 1; hashpile(from); hashpile(to); #if PRINT print_layout(); #endif }
void GolfSolver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from = m->from; int to = m->to; Q_ASSERT( to == 7 ); Q_ASSERT( from != 7 ); // move to pile if ( from == 8 && to == 7 ) { card_t card = *Wp[8]; Wp[8]--; Wlen[8]--; card = ( SUIT( card ) << 4 ) + RANK( card ); Wp[7]++; *Wp[7] = card; Wlen[7]++; hashpile( 7 ); hashpile( 8 ); #if PRINT print_layout(); #endif return; } card_t card = *Wp[from]; Wp[from]--; Wlen[from]--; Wp[to]++; *Wp[to] = card; Wlen[to]++; hashpile(from); hashpile(to); #if PRINT print_layout(); #endif }
void IdiotSolver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from, to; card_t card = NONE; from = m->from; to = m->to; if ( from == 4 ) { Q_ASSERT( Wlen[from] >= 4 ); for ( int i = 0; i < 4; ++i ) { Wp[i]++; card = *Wp[from]; *Wp[i] = ( SUIT( card ) << 4 ) + RANK( card ); Wp[from]--; Wlen[from]--; Wlen[i]++; hashpile( i ); } hashpile( from ); } else { card = *Wp[from]; Wp[from]--; Wlen[from]--; *Wp[to]++; *Wp[to] = card; Wlen[to]++; hashpile( to ); hashpile(from); } #if PRINT print_layout(); #endif }
void IdiotSolver::undo_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; if ( from == 4 ) { for ( int i = 3; i >= 0; --i ) { card = *Wp[i]; Wp[i]--; Wlen[i]--; Wp[from]++; *Wp[from] = ( SUIT( card ) << 4 ) + RANK( card ) + ( 1 << 7 ); Wlen[from]++; hashpile( i ); } hashpile( from ); } else { card = *Wp[to]; Wp[to]--; Wlen[to]--; *Wp[from]++; *Wp[from] = card; Wlen[from]++; hashpile( to ); hashpile(from); } #if PRINT print_layout(); #endif }
void ClockSolver::undo_move(MOVE *m) { #if PRINT2 if ( m->totype == O_Type ) fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; if (m->totype == O_Type) { card = W[8][to]; if ( RANK( card ) == PS_ACE ) W[8][to] = W[8][to] - PS_ACE + PS_KING; else W[8][to]--; Wp[from]++; *Wp[from] = card; Wlen[from]++; hashpile( 8 ); hashpile( from ); } else { card = *Wp[to]; Wp[from]++; *Wp[from] = card; Wlen[from]++; Wp[to]--; Wlen[to]--; hashpile(to); hashpile( from ); } #if PRINT2 print_layout(); #endif }
void ClockSolver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out %d (at %d)\n\n", m->card_index, m->from, m->to, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from, to; from = m->from; to = m->to; card_t card = *Wp[from]; Wlen[from]--; Wp[from]--; hashpile(from); /* Add to pile. */ if (m->totype == O_Type) { if ( RANK( W[8][to] ) == PS_KING ) W[8][to] = W[8][to] - PS_KING + PS_ACE; else W[8][to]++; Q_ASSERT( m->card_index == 0 ); hashpile( 8 ); } else { Wp[to]++; *Wp[to] = card; Wlen[to]++; hashpile( to ); } #if PRINT print_layout(); #endif }
void FreecellSolver::undo_move(MOVE *m) { int from, to; card_t card; from = m->from; to = m->to; /* Remove from 'to' pile. */ if (m->totype == O_Type) { card = O[to] + Osuit[to]; O[to]--; } else { card = *Wp[to]--; Wlen[to]--; hashpile(to); } /* Add to 'from' pile. */ *++Wp[from] = card; Wlen[from]++; hashpile(from); }
void FreecellSolver::make_move(MOVE *m) { int from, to; card_t card; from = m->from; to = m->to; /* Remove from pile. */ card = *Wp[from]--; Wlen[from]--; hashpile(from); /* Add to pile. */ if (m->totype == O_Type) { O[to]++; } else { *++Wp[to] = card; Wlen[to]++; hashpile(to); } }
void GypsySolver::make_move(MOVE *m) { #if PRINT kDebug() << "\n\nmake_move\n"; if ( m->totype == O_Type ) fprintf( stderr, "move %d from %d out (at %d) Prio: %d\n\n", m->card_index, m->from, m->turn_index, m->pri ); else fprintf( stderr, "move %d from %d to %d (%d) Prio: %d\n\n", m->card_index, m->from, m->to, m->turn_index, m->pri ); print_layout(); #else //print_layout(); #endif int from, to; //card_t card = NONE; from = m->from; to = m->to; if ( m->from == deck ) { for ( int i = 0; i < 8; ++i ) { card_t card = *Wp[from]; card = ( SUIT( card ) << 4 ) + RANK( card ); ++Wp[i]; *Wp[i] = card; --Wp[from]; Wlen[i]++; hashpile( i ); Wlen[from]--; } hashpile( from ); #if PRINT print_layout(); #endif return; } card_t card = NONE; for ( int l = m->card_index; l >= 0; --l ) { card = W[from][Wlen[from]-l-1]; Wp[from]--; if ( m->totype != O_Type ) { Wp[to]++; *Wp[to] = card; Wlen[to]++; } } Wlen[from] -= m->card_index + 1; if ( m->turn_index == 0 ) { if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); W[to][Wlen[to]-m->card_index-1] = card; } else if ( m->turn_index != -1 ) { card_t card2 = *Wp[from]; if ( DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ); *Wp[from] = card2; } hashpile(from); /* Add to pile. */ if (m->totype == O_Type) { if ( Wlen[to] ) *Wp[to] = card; else { Wp[to]++; Wlen[to]++; *Wp[to] = card; } Q_ASSERT( m->card_index == 0 ); } hashpile(to); #if PRINT print_layout(); #endif }
void KlondikeSolver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from, to; card_t card = NONE; from = m->from; to = m->to; /* Remove from pile. */ if ( from == 7 && to == 8 ) { while ( Wlen[7] ) { card = W[7][Wlen[7]-1] + ( 1 << 7 ); Wlen[8]++; W[8][Wlen[8]-1] = card; Wlen[7]--; } Wp[7] = &W[7][0]; Wp[8] = &W[8][Wlen[8]-1]; hashpile( 7 ); hashpile( 8 ); #if PRINT print_layout(); #endif return; } // move to pile if ( from == 8 && to == 7 ) { for ( int i = 0; i < m->card_index; ++i ) { if ( !Wlen[8] ) continue; card = *Wp[8]; Wp[8]--; Wlen[8]--; card = ( SUIT( card ) << 4 ) + RANK( card ); Wp[7]++; *Wp[7] = card; Wlen[7]++; } hashpile( 7 ); hashpile( 8 ); #if PRINT print_layout(); #endif return; } for ( int l = m->card_index; l >= 0; --l ) { card = W[from][Wlen[from]-l-1]; Wp[from]--; if ( m->totype != O_Type ) { Wp[to]++; *Wp[to] = card; Wlen[to]++; } } Wlen[from] -= m->card_index + 1; if ( m->turn_index == 0 ) { if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); W[to][Wlen[to]-m->card_index-1] = card; } else if ( m->turn_index != -1 ) { card_t card2 = *Wp[from]; if ( DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ); *Wp[from] = card2; } hashpile(from); /* Add to pile. */ if (m->totype == O_Type) { O[to]++; Q_ASSERT( m->card_index == 0 ); } else { hashpile(to); } #if PRINT print_layout(); #endif }
void KlondikeSolver::undo_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; /* Remove from 'to' pile. */ if ( from == 7 && to == 8 ) { while ( Wlen[8] ) { card = W[8][Wlen[8]-1]; card = ( SUIT( card ) << 4 ) + RANK( card ); Wlen[7]++; W[7][Wlen[7]-1] = card; Wlen[8]--; } Wp[8] = &W[8][0]; Wp[7] = &W[7][Wlen[7]-1]; hashpile( 7 ); hashpile( 8 ); #if PRINT print_layout(); #endif return; } // move back to deck if ( from == 8 && to == 7 ) { for ( int i = 0; i < m->card_index; ++i ) { card = *Wp[7]; Wp[7]--; Wlen[7]--; card = ( SUIT( card ) << 4 ) + RANK( card ) + ( 1 << 7 ); Wp[8]++; *Wp[8] = card; Wlen[8]++; } hashpile( 7 ); hashpile( 8 ); #if PRINT print_layout(); #endif return; } /* Add to 'from' pile. */ if ( m->turn_index > 0 ) { card_t card2 = *Wp[from]; if ( !DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ) + ( 1 << 7 ); *Wp[from] = card2; } if (m->totype == O_Type) { card = O[to] + Osuit[to]; O[to]--; Wp[from]++; *Wp[from] = card; Wlen[from]++; } else { for ( int l = m->card_index; l >= 0; --l ) { card = W[to][Wlen[to]-l-1]; Wp[from]++; *Wp[from] = card; Wlen[from]++; Wp[to]--; } Wlen[to] -= m->card_index + 1; hashpile(to); } if ( m->turn_index == 0 ) { card_t card = *Wp[from]; if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); *Wp[from] = card; } hashpile(from); #if PRINT print_layout(); #endif }
void GypsySolver::undo_move(MOVE *m) { #if PRINT kDebug() << "\n\nundo_move\n"; if ( m->totype == O_Type ) fprintf( stderr, "move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; //card_t card; from = m->from; to = m->to; if ( m->from == deck ) { for ( int i = 7; i >= 0; --i ) { card_t card = *Wp[i]; Q_ASSERT( !DOWN( card ) ); card = ( SUIT( card ) << 4 ) + RANK( card ) + ( 1 << 7 ); ++Wp[from]; --Wp[i]; *Wp[from] = card; Wlen[from]++; Wlen[i]--; hashpile( i ); } hashpile( from ); #if PRINT print_layout(); #endif return; } /* Add to 'from' pile. */ if ( m->turn_index > 0 ) { card_t card2 = *Wp[from]; if ( !DOWN( card2 ) ) card2 = ( SUIT( card2 ) << 4 ) + RANK( card2 ) + ( 1 << 7 ); *Wp[from] = card2; } card_t card = NONE; if (m->totype == O_Type) { card = *Wp[to]; if ( RANK( card ) == PS_ACE ) { Wlen[to] = 0; } else { *Wp[to] = card - 1; // SUIT( card ) << 4 + RANK( card ) - 1; } Wp[from]++; *Wp[from] = card; Wlen[from]++; hashpile( to ); } else { for ( int l = m->card_index; l >= 0; --l ) { card = W[to][Wlen[to]-l-1]; Wp[from]++; *Wp[from] = card; Wlen[from]++; Wp[to]--; } Wlen[to] -= m->card_index + 1; hashpile(to); } if ( m->turn_index == 0 ) { card_t card = *Wp[from]; if ( DOWN( card ) ) card = ( SUIT( card ) << 4 ) + RANK( card ); else card += ( 1 << 7 ); *Wp[from] = card; } hashpile(from); #if PRINT print_layout(); #endif }
void Mod3Solver::make_move(MOVE *m) { #if PRINT if ( m->totype == O_Type ) fprintf( stderr, "\nmake move %d from %d out %d (at %d)\n\n", m->card_index, m->from, m->to, m->turn_index ); else fprintf( stderr, "\nmake move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #else //print_layout(); #endif int from, to; from = m->from; to = m->to; if ( from == deck ) { int len = m->card_index; if ( len > 8 ) len = 8; for ( int i = 0; i < len; i++ ) { card_t card = *Wp[deck]; Wlen[deck]--; Wp[deck]--; card = ( card & PS_SUIT ) + RANK( card ); Wp[24 + i]++; Wlen[24 + i]++; *Wp[24 + i] = card; hashpile( 24 + i ); } hashpile( deck ); #if PRINT print_layout(); #endif return; } card_t card = *Wp[from]; Wlen[from]--; Wp[from]--; hashpile( from ); /* Add to pile. */ Wp[to]++; *Wp[to] = card; Wlen[to]++; hashpile( to ); if ( m->turn_index == 1 ) { card_t card2 = *Wp[deck]; Wlen[deck]--; Wp[deck]--; hashpile(deck); /* Add to pile. */ Wp[from]++; *Wp[from] = RANK( card2 ) + ( SUIT( card2 ) << 4 ); Wlen[from]++; } hashpile(from); #if PRINT print_layout(); #endif }
void Mod3Solver::undo_move(MOVE *m) { #if PRINT2 if ( m->totype == O_Type ) fprintf( stderr, "\nundo move %d from %d out (at %d)\n\n", m->card_index, m->from, m->turn_index ); else fprintf( stderr, "\nundo move %d from %d to %d (%d)\n\n", m->card_index, m->from, m->to, m->turn_index ); print_layout(); #endif int from, to; card_t card; from = m->from; to = m->to; if ( from == deck ) { int len = m->card_index; if ( len > 8 ) len = 8; for ( int i = len; i >= 0; i-- ) { card_t card = *Wp[24+i]; Wlen[deck]++; Wp[deck]++; *Wp[deck] = ( 1 << 7 ) + card; Wp[24 + i]--; Wlen[24 + i]--; hashpile( 24 + i ); } hashpile( deck ); #if PRINT2 print_layout(); #endif return; } if ( m->turn_index == 1) { card_t card = *Wp[from]; Wp[deck]++; Wlen[deck]++; *Wp[deck] = ( 1 << 7 ) + card; Wlen[from]--; Wp[from]--; hashpile(deck); } card = *Wp[to]; Wp[from]++; *Wp[from] = card; Wlen[from]++; Wp[to]--; Wlen[to]--; hashpile(to); hashpile( from ); #if PRINT2 print_layout(); #endif }