when no moves found, reset engine and try again. Works around bug

where you do "hint", then "prev hint" and get told there are no moves
found only to have the next "prev hint" succeed. This is a hack, but
the right fix is eluding me, and will certainly be riskier.
This commit is contained in:
Eric House 2015-08-19 07:43:00 -07:00
parent 6d7123c27a
commit 255ca56ed7

View file

@ -345,9 +345,6 @@ chooseMove( EngineCtxt* engine, PossibleMove** move )
result = (NULL != chosen) && (chosen->score > 0);
if ( !result ) {
engine_reset( engine );
}
return result;
} /* chooseMove */
@ -381,7 +378,7 @@ normalizeIQ( EngineCtxt* engine, XP_U16 iq )
XP_Bool
engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
XP_U16 turn, const Tile* tiles,
XP_U16 nTiles, XP_Bool usePrev,
const XP_U16 nTiles, XP_Bool usePrev,
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus,
#endif
@ -394,7 +391,9 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
XP_Bool result = XP_TRUE;
XP_U16 star_row;
XP_Bool canMove = XP_FALSE;
XP_Bool isRetry = XP_FALSE;
retry:
engine->nTilesMax = XP_MIN( MAX_TRAY_TILES, nTiles );
#ifdef XWFEATURE_BONUSALL
engine->allTilesBonus = allTilesBonus;
@ -542,6 +541,22 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
newMove->nTiles = 0;
}
/* Gross hack alert: there's an elusive bug in move cacheing that means
when we move forward or back from the highest-scoring move to the
lowest (or vice-versa) no move is found. But the next try succeeds,
because an engine_reset clears the state that makes that happen. So as
a workaround, try doing that when no moves are found. If none is found
for some other reason, e.g. no tiles, at least the search should be
quick. */
if ( !canMove ) {
engine_reset( engine );
if ( !isRetry ) {
isRetry = XP_TRUE;
XP_LOGF( "%s: no moves found so retrying", __func__ );
goto retry;
}
}
*canMoveP = canMove;
return result;
} /* engine_findMove */