diff --git a/patsolve/mod3solver.cpp b/patsolve/mod3solver.cpp --- a/patsolve/mod3solver.cpp +++ b/patsolve/mod3solver.cpp @@ -122,6 +122,12 @@ len = 8; for ( int i = len; i >= 0; i-- ) { + if (Wlen[i] == 0) { + // there exists no card to move + /* TODO: determine if we need to call hashpile here + / or do any other work */ + continue; + } card_t card = *Wp[24+i]; Wlen[deck]++; Wp[deck]++; @@ -249,7 +255,12 @@ if ( Wlen[i] == Wlen[j] + 1 ) continue; } - mp->pri = qMin(119, 12 + 20 * Wlen[j] + current_row * 2 + RANK(*Wp[j]) * 5); + + if (Wlen[j]) { + mp->pri = qMin(119, 12 + 20 * Wlen[j] + current_row * 2 + RANK(*Wp[j]) * 5); + } else { + mp->pri = 119; // TODO: Find out if this is really correct. We can certainly not touch Wp[j], b ut is this the correct mp->pri value? + } mp->turn_index = -1; if ( i >= 24 && Wlen[i] == 1 && Wlen[deck] ) diff --git a/patsolve/spidersolver.cpp b/patsolve/spidersolver.cpp --- a/patsolve/spidersolver.cpp +++ b/patsolve/spidersolver.cpp @@ -310,6 +310,7 @@ bool wasempty = false; for (int j = 0; j < 10; ++j) { + if (i == j) continue; @@ -345,7 +346,8 @@ printcard( card, stderr ); fprintf( stderr, "%d %d %d %d %d\n", i, j, conti[i], conti[j],l ); #endif - if ( SUIT( card ) != SUIT( *Wp[j] ) ) + bool card_stack_j_not_empty = Wlen[j] > 0; + if (card_stack_j_not_empty && SUIT( card ) != SUIT( *Wp[j] ) ) { //fprintf( stderr, "continue %d %d %d %d\n",conti[j]+l, conti[i],conti[j]+l, SUIT( card ) != SUIT( *Wp[j] ) ); continue; @@ -383,8 +385,16 @@ else { if ( conti[j]+l+1 != 13 || conti[i]>conti[j]+l ) { - card_t card_below = W[i][Wlen[i]-l-2]; - if ( SUIT( card_below ) != SUIT( card ) || RANK(card_below) != RANK(card) + 1 ) + card_t card_below; + bool exists_card_below = Wlen[i] >= l + 2; + if (exists_card_below) { + card_below = W[i][Wlen[i]-l-2]; + } + if ( !exists_card_below || ( exists_card_below && + ( SUIT( card_below ) != SUIT( card ) || + RANK(card_below) != RANK(card) + 1 ) + ) + ) { foundgood = true; } else { @@ -426,6 +436,9 @@ n++; mp++; + if (n >= MAXMOVES) { + goto cannot_store_any_more_moves; + } } } } @@ -446,6 +459,8 @@ break; // one is enough } +cannot_store_any_more_moves: + if ( n > toomuch && foundgood) { mp = Possible;