Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit b58fd275 authored by Fabian Kosmale's avatar Fabian Kosmale Committed by Albert Astals Cid

Summary: SpiderSolitaire: Check if there exists a card below before accessing it

BUG: 389540

Reviewers: #kde_games

Subscribers: aacid, #kde_games

Differential Revision: https://phabricator.kde.org/D10889
parent dd92d0e9
......@@ -122,6 +122,12 @@ void Mod3Solver::undo_move(MOVE *m)
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 @@ int Mod3Solver::get_possible_moves(int *a, int *numout)
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] )
......
......@@ -310,6 +310,7 @@ int SpiderSolver::get_possible_moves(int *a, int *numout)
bool wasempty = false;
for (int j = 0; j < 10; ++j)
{
if (i == j)
continue;
......@@ -345,7 +346,8 @@ int SpiderSolver::get_possible_moves(int *a, int *numout)
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 @@ int SpiderSolver::get_possible_moves(int *a, int *numout)
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 @@ int SpiderSolver::get_possible_moves(int *a, int *numout)
n++;
mp++;
if (n >= MAXMOVES) {
goto cannot_store_any_more_moves;
}
}
}
}
......@@ -446,6 +459,8 @@ int SpiderSolver::get_possible_moves(int *a, int *numout)
break; // one is enough
}
cannot_store_any_more_moves:
if ( n > toomuch && foundgood)
{
mp = Possible;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment