mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-07 05:24:46 +01:00
cleanup: use temp ptr to avoid too many dereferences
This commit is contained in:
parent
a11e5beded
commit
884eda0603
1 changed files with 44 additions and 42 deletions
|
@ -1146,23 +1146,24 @@ considerScoreWordHasBlanks( EngineCtxt* engine, XP_U16 blanksLeft,
|
|||
static void
|
||||
saveMoveIfQualifies( EngineCtxt* engine, PossibleMove* posmove )
|
||||
{
|
||||
XP_S16 mostest = 0;
|
||||
XP_S16 mostest;
|
||||
XP_S16 cmpVal;
|
||||
XP_Bool usePrev = engine->usePrev;
|
||||
XP_Bool foundEmpty = XP_FALSE;
|
||||
MoveIterationData* miData = &engine->miData;
|
||||
|
||||
if ( 1 == engine->nMovesToSave ) { /* only saving one */
|
||||
mostest = 0;
|
||||
} else {
|
||||
mostest = -1;
|
||||
/* we're not interested if we've seen this */
|
||||
cmpVal = CMPMOVES( posmove, &engine->miData.lastSeenMove );
|
||||
cmpVal = CMPMOVES( posmove, &miData->lastSeenMove );
|
||||
if ( !usePrev && cmpVal >= 0 ) {
|
||||
/* XP_LOGF( "%s: dropping %d: higher than %d", __func__, */
|
||||
/* posmove->score, engine->miData.lastSeenMove.score ); */
|
||||
/* XP_LOGF( "%s: dropping %d: >= %d", __func__, */
|
||||
/* posmove->score, miData->lastSeenMove.score ); */
|
||||
} else if ( usePrev && cmpVal <= 0 ) {
|
||||
/* XP_LOGF( "%s: dropping %d: lower than %d", __func__, */
|
||||
/* posmove->score, engine->miData.lastSeenMove.score ); */
|
||||
/* XP_LOGF( "%s: dropping %d: <= %d", __func__, */
|
||||
/* posmove->score, miData->lastSeenMove.score ); */
|
||||
} else {
|
||||
XP_S16 ii;
|
||||
/* terminate i at 1 because mostest starts at 0 */
|
||||
|
@ -1178,19 +1179,19 @@ saveMoveIfQualifies( EngineCtxt* engine, PossibleMove* posmove )
|
|||
/* 1/20/2001 I don't see that this assertion is valid. I
|
||||
simply don't understand why it isn't tripped all the time
|
||||
in the old crosswords. */
|
||||
/* XP_ASSERT( (engine->miData.lastSeenMove.score == 0x7fff) */
|
||||
/* || (engine->miData.savedMoves[i].score */
|
||||
/* XP_ASSERT( (miData->lastSeenMove.score == 0x7fff) */
|
||||
/* || (miData->savedMoves[i].score */
|
||||
/* <= posmove->score) ); */
|
||||
|
||||
if ( 0 == engine->miData.savedMoves[ii].score ) {
|
||||
if ( 0 == miData->savedMoves[ii].score ) {
|
||||
foundEmpty = XP_TRUE;
|
||||
mostest = ii;
|
||||
break;
|
||||
} else if ( -1 == mostest ) {
|
||||
mostest = ii;
|
||||
} else {
|
||||
cmpVal = CMPMOVES( &engine->miData.savedMoves[mostest],
|
||||
&engine->miData.savedMoves[ii] );
|
||||
cmpVal = CMPMOVES( &miData->savedMoves[mostest],
|
||||
&miData->savedMoves[ii] );
|
||||
if ( !usePrev && cmpVal > 0 ) {
|
||||
mostest = ii;
|
||||
} else if ( usePrev && cmpVal < 0 ) {
|
||||
|
@ -1204,14 +1205,14 @@ saveMoveIfQualifies( EngineCtxt* engine, PossibleMove* posmove )
|
|||
while ( mostest >= 0 ) { /* while: so we can break */
|
||||
/* record the score we're dumping. No point in considering any scores
|
||||
lower than this for the rest of this round. */
|
||||
/* engine->miData.lowestSavedScore = */
|
||||
/* engine->miData.savedMoves[lowest].score; */
|
||||
/* miData->lowestSavedScore = */
|
||||
/* miData->savedMoves[lowest].score; */
|
||||
/* XP_DEBUGF( "lowestSavedScore now %d\n", */
|
||||
/* engine->miData.lowestSavedScore ); */
|
||||
/* miData->lowestSavedScore ); */
|
||||
if ( foundEmpty ) {
|
||||
/* we're good */
|
||||
} else {
|
||||
cmpVal = CMPMOVES( posmove, &engine->miData.savedMoves[mostest]);
|
||||
cmpVal = CMPMOVES( posmove, &miData->savedMoves[mostest]);
|
||||
if ( !usePrev && cmpVal <= 0 ) {
|
||||
break;
|
||||
} else if ( usePrev && cmpVal >= 0 ) {
|
||||
|
@ -1219,10 +1220,10 @@ saveMoveIfQualifies( EngineCtxt* engine, PossibleMove* posmove )
|
|||
}
|
||||
}
|
||||
/* XP_LOGF( "saving move with score %d at %d (replacing %d)\n", */
|
||||
/* posmove->score, mostest, */
|
||||
/* engine->miData.savedMoves[mostest].score ); */
|
||||
XP_MEMCPY( &engine->miData.savedMoves[mostest], posmove,
|
||||
sizeof(engine->miData.savedMoves[mostest]) );
|
||||
/* posmove->score, mostest, */
|
||||
/* miData->savedMoves[mostest].score ); */
|
||||
XP_MEMCPY( &miData->savedMoves[mostest], posmove,
|
||||
sizeof(miData->savedMoves[mostest]) );
|
||||
break;
|
||||
}
|
||||
} /* saveMoveIfQualifies */
|
||||
|
@ -1230,15 +1231,16 @@ saveMoveIfQualifies( EngineCtxt* engine, PossibleMove* posmove )
|
|||
static void
|
||||
set_search_limits( EngineCtxt* engine )
|
||||
{
|
||||
MoveIterationData* miData = &engine->miData;
|
||||
/* If we're going to be searching backwards we want our highest cached
|
||||
move as the limit; otherwise the lowest */
|
||||
if ( 0 < engine->miData.nInMoveCache ) {
|
||||
if ( 0 < miData->nInMoveCache ) {
|
||||
XP_U16 srcIndx = engine->usePrev
|
||||
? engine->nMovesToSave-1 : engine->miData.bottom;
|
||||
XP_MEMCPY( &engine->miData.lastSeenMove,
|
||||
&engine->miData.savedMoves[srcIndx],
|
||||
sizeof(engine->miData.lastSeenMove) );
|
||||
//engine->miData.lowestSavedScore = 0;
|
||||
? engine->nMovesToSave-1 : miData->bottom;
|
||||
XP_MEMCPY( &miData->lastSeenMove,
|
||||
&miData->savedMoves[srcIndx],
|
||||
sizeof(miData->lastSeenMove) );
|
||||
//miData->lowestSavedScore = 0;
|
||||
} else {
|
||||
/* we're doing this for first time */
|
||||
engine_reset( engine );
|
||||
|
@ -1249,41 +1251,40 @@ static void
|
|||
init_move_cache( EngineCtxt* engine )
|
||||
{
|
||||
XP_U16 nInMoveCache = engine->nMovesToSave;
|
||||
MoveIterationData* miData = &engine->miData;
|
||||
XP_U16 ii;
|
||||
|
||||
XP_ASSERT( engine->nMovesToSave == NUM_SAVED_ENGINE_MOVES );
|
||||
|
||||
for ( ii = 0; ii < NUM_SAVED_ENGINE_MOVES; ++ii ) {
|
||||
if ( 0 == engine->miData.savedMoves[ii].score ) {
|
||||
if ( 0 == miData->savedMoves[ii].score ) {
|
||||
--nInMoveCache;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
engine->miData.nInMoveCache = nInMoveCache;
|
||||
engine->miData.bottom = NUM_SAVED_ENGINE_MOVES - nInMoveCache;
|
||||
miData->nInMoveCache = nInMoveCache;
|
||||
miData->bottom = NUM_SAVED_ENGINE_MOVES - nInMoveCache;
|
||||
|
||||
if ( engine->usePrev ) {
|
||||
engine->miData.curCacheIndex =
|
||||
NUM_SAVED_ENGINE_MOVES - nInMoveCache - 1;
|
||||
} else {
|
||||
engine->miData.curCacheIndex = NUM_SAVED_ENGINE_MOVES;
|
||||
}
|
||||
miData->curCacheIndex = engine->usePrev
|
||||
? NUM_SAVED_ENGINE_MOVES - nInMoveCache - 1
|
||||
: NUM_SAVED_ENGINE_MOVES;
|
||||
}
|
||||
|
||||
static PossibleMove*
|
||||
next_from_cache( EngineCtxt* engine )
|
||||
{
|
||||
MoveIterationData* miData = &engine->miData;
|
||||
PossibleMove* move;
|
||||
if ( move_cache_empty( engine ) ) {
|
||||
move = NULL;
|
||||
} else {
|
||||
if ( engine->usePrev ) {
|
||||
++engine->miData.curCacheIndex;
|
||||
++miData->curCacheIndex;
|
||||
} else {
|
||||
--engine->miData.curCacheIndex;
|
||||
--miData->curCacheIndex;
|
||||
}
|
||||
move = &engine->miData.savedMoves[engine->miData.curCacheIndex];
|
||||
move = &miData->savedMoves[miData->curCacheIndex];
|
||||
}
|
||||
return move;
|
||||
}
|
||||
|
@ -1309,21 +1310,22 @@ scoreQualifies( EngineCtxt* engine, XP_U16 score )
|
|||
{
|
||||
XP_Bool qualifies = XP_FALSE;
|
||||
XP_Bool usePrev = engine->usePrev;
|
||||
MoveIterationData* miData = &engine->miData;
|
||||
|
||||
if ( usePrev && score < engine->miData.lastSeenMove.score ) {
|
||||
if ( usePrev && score < miData->lastSeenMove.score ) {
|
||||
/* drop it */
|
||||
} else if ( !usePrev && score > engine->miData.lastSeenMove.score
|
||||
/* || (score < engine->miData.lowestSavedScore) */ ) {
|
||||
} else if ( !usePrev && score > miData->lastSeenMove.score
|
||||
/* || (score < miData->lowestSavedScore) */ ) {
|
||||
/* drop it */
|
||||
} else {
|
||||
XP_S16 ii;
|
||||
PossibleMove* savedMoves = engine->miData.savedMoves;
|
||||
PossibleMove* savedMoves = miData->savedMoves;
|
||||
/* Look at each saved score, and return true as soon as one's found
|
||||
with a lower or equal score to this. <eeh> As an optimization,
|
||||
consider remembering what the lowest score is *once there are
|
||||
NUM_SAVED_ENGINE_MOVES moves in here* and doing a quick test on
|
||||
that. Or better, keeping the list in sorted order. */
|
||||
for ( ii = 0, savedMoves = engine->miData.savedMoves;
|
||||
for ( ii = 0, savedMoves = miData->savedMoves;
|
||||
ii < engine->nMovesToSave; ++ii, ++savedMoves ) {
|
||||
if ( savedMoves->score == 0 ) { /* empty slot */
|
||||
qualifies = XP_TRUE;
|
||||
|
|
Loading…
Reference in a new issue