mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-29 08:34:37 +01:00
fix bug summarizing score for one-tile moves; remove return from
middle of function.
This commit is contained in:
parent
cddb31c22d
commit
969d69f3ae
1 changed files with 97 additions and 88 deletions
185
common/mscore.c
185
common/mscore.c
|
@ -489,11 +489,19 @@ figureMoveScore( ModelCtxt* model, MoveInfo* moveInfo, EngineCtxt* engine,
|
||||||
|
|
||||||
for ( i = 0, tiles = moveInfo->tiles; i < nTiles; ++i, ++tiles ) {
|
for ( i = 0, tiles = moveInfo->tiles; i < nTiles; ++i, ++tiles ) {
|
||||||
|
|
||||||
|
/* Moves using only one tile will sometimes score only in the
|
||||||
|
crosscheck direction. Score may still be 0 after the call to
|
||||||
|
scoreWord above. Keep trying to get some text in mainWord until
|
||||||
|
something's been scored. */
|
||||||
|
if ( score > 0 ) {
|
||||||
|
mainWord = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tmpMI.commonCoord = tiles->varCoord;
|
tmpMI.commonCoord = tiles->varCoord;
|
||||||
tmpMI.tiles[0].tile = tiles->tile;
|
tmpMI.tiles[0].tile = tiles->tile;
|
||||||
|
|
||||||
oneScore = scoreWord( model, &tmpMI, engine, stream, silent,
|
oneScore = scoreWord( model, &tmpMI, engine, stream, silent,
|
||||||
notifyInfo, NULL );
|
notifyInfo, mainWord );
|
||||||
if ( !!stream ) {
|
if ( !!stream ) {
|
||||||
formatWordScore( stream, oneScore, multipliers[i] );
|
formatWordScore( stream, oneScore, multipliers[i] );
|
||||||
}
|
}
|
||||||
|
@ -557,7 +565,8 @@ scoreWord( ModelCtxt* model, MoveInfo* movei, /* new tiles */
|
||||||
XP_UCHAR* mainWord )
|
XP_UCHAR* mainWord )
|
||||||
{
|
{
|
||||||
XP_U16 tileMultiplier;
|
XP_U16 tileMultiplier;
|
||||||
XP_U16 restScore, scoreFromCache;
|
XP_U16 restScore = 0;
|
||||||
|
XP_U16 scoreFromCache;
|
||||||
XP_U16 thisTileValue;
|
XP_U16 thisTileValue;
|
||||||
XP_U16 nTiles = movei->nTiles;
|
XP_U16 nTiles = movei->nTiles;
|
||||||
Tile tile;
|
Tile tile;
|
||||||
|
@ -567,11 +576,6 @@ scoreWord( ModelCtxt* model, MoveInfo* movei, /* new tiles */
|
||||||
MoveInfoTile* tiles = movei->tiles;
|
MoveInfoTile* tiles = movei->tiles;
|
||||||
XP_U16 firstCoord = tiles->varCoord;
|
XP_U16 firstCoord = tiles->varCoord;
|
||||||
DictionaryCtxt* dict = model->vol.dict;
|
DictionaryCtxt* dict = model->vol.dict;
|
||||||
WordScoreFormatter fmtr;
|
|
||||||
|
|
||||||
if ( !!stream || !!mainWord ) {
|
|
||||||
wordScoreFormatterInit( &fmtr, dict );
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( movei->isHorizontal ) {
|
if ( movei->isHorizontal ) {
|
||||||
row = movei->commonCoord;
|
row = movei->commonCoord;
|
||||||
|
@ -588,110 +592,115 @@ scoreWord( ModelCtxt* model, MoveInfo* movei, /* new tiles */
|
||||||
*incr = tiles[0].varCoord;
|
*incr = tiles[0].varCoord;
|
||||||
start = find_start( model, col, row, movei->isHorizontal );
|
start = find_start( model, col, row, movei->isHorizontal );
|
||||||
|
|
||||||
if ( (end - start) < 1 ) { /* one-letter word: score 0 */
|
if ( (end - start) >= 1 ) { /* one-letter word: score 0 */
|
||||||
return 0;
|
WordScoreFormatter fmtr;
|
||||||
}
|
if ( !!stream || !!mainWord ) {
|
||||||
|
wordScoreFormatterInit( &fmtr, dict );
|
||||||
|
}
|
||||||
|
|
||||||
if ( IS_BLANK(tiles->tile) ) {
|
if ( IS_BLANK(tiles->tile) ) {
|
||||||
tile = dict_getBlankTile( dict );
|
tile = dict_getBlankTile( dict );
|
||||||
} else {
|
} else {
|
||||||
tile = tiles->tile & TILE_VALUE_MASK;
|
tile = tiles->tile & TILE_VALUE_MASK;
|
||||||
}
|
}
|
||||||
thisTileValue = dict_getTileValue( dict, tile );
|
thisTileValue = dict_getTileValue( dict, tile );
|
||||||
|
|
||||||
XP_ASSERT( *incr == tiles[0].varCoord );
|
XP_ASSERT( *incr == tiles[0].varCoord );
|
||||||
thisTileValue *= tile_multiplier( model, col, row );
|
thisTileValue *= tile_multiplier( model, col, row );
|
||||||
|
|
||||||
XP_ASSERT( engine == NULL || nTiles == 1 );
|
XP_ASSERT( engine == NULL || nTiles == 1 );
|
||||||
|
|
||||||
if ( engine != NULL ) {
|
if ( engine != NULL ) {
|
||||||
XP_ASSERT( nTiles==1 );
|
XP_ASSERT( nTiles==1 );
|
||||||
scoreFromCache = engine_getScoreCache( engine, movei->commonCoord );
|
scoreFromCache = engine_getScoreCache( engine, movei->commonCoord );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for a while, at least, calculate and use the cached crosscheck score
|
/* for a while, at least, calculate and use the cached crosscheck score
|
||||||
* each time through in the debug case */
|
* each time through in the debug case */
|
||||||
if ( 0 ) { /* makes keeping parens balanced easier */
|
if ( 0 ) { /* makes keeping parens balanced easier */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
} else if ( 1 ) {
|
} else if ( 1 ) {
|
||||||
#else
|
#else
|
||||||
} else if ( engine == NULL ) {
|
} else if ( engine == NULL ) {
|
||||||
#endif
|
#endif
|
||||||
Tile checkWordBuf[MAX_ROWS];
|
Tile checkWordBuf[MAX_ROWS];
|
||||||
Tile* curTile = checkWordBuf;
|
Tile* curTile = checkWordBuf;
|
||||||
|
|
||||||
restScore = 0;
|
for ( *incr = start; *incr <= end; ++*incr ) {
|
||||||
for ( *incr = start; *incr <= end; ++*incr ) {
|
XP_U16 tileScore = 0;
|
||||||
XP_U16 tileScore = 0;
|
XP_Bool isBlank;
|
||||||
XP_Bool isBlank;
|
|
||||||
|
|
||||||
/* a new move? */
|
/* a new move? */
|
||||||
if ( (nTiles > 0) && (*incr == tiles->varCoord) ) {
|
if ( (nTiles > 0) && (*incr == tiles->varCoord) ) {
|
||||||
tile = tiles->tile & TILE_VALUE_MASK;
|
tile = tiles->tile & TILE_VALUE_MASK;
|
||||||
isBlank = IS_BLANK(tiles->tile);
|
isBlank = IS_BLANK(tiles->tile);
|
||||||
/* don't call localGetBlankTile when in silent (robot called)
|
/* don't call localGetBlankTile when in silent (robot called)
|
||||||
* mode, as the blank won't be known there. (Assert will
|
* mode, as the blank won't be known there. (Assert will
|
||||||
* fail.) */
|
* fail.) */
|
||||||
|
|
||||||
tileMultiplier = tile_multiplier( model, col, row );
|
tileMultiplier = tile_multiplier( model, col, row );
|
||||||
++tiles;
|
++tiles;
|
||||||
--nTiles;
|
--nTiles;
|
||||||
} else { /* placed on the board before this move */
|
} else { /* placed on the board before this move */
|
||||||
XP_Bool ignore;
|
XP_Bool ignore;
|
||||||
tileMultiplier = 1;
|
tileMultiplier = 1;
|
||||||
|
|
||||||
(void)model_getTile( model, col, row, XP_FALSE, -1, &tile,
|
(void)model_getTile( model, col, row, XP_FALSE, -1, &tile,
|
||||||
&isBlank, &ignore, (XP_Bool*)NULL );
|
&isBlank, &ignore, (XP_Bool*)NULL );
|
||||||
|
|
||||||
XP_ASSERT( (tile & TILE_VALUE_MASK) == tile );
|
XP_ASSERT( (tile & TILE_VALUE_MASK) == tile );
|
||||||
|
}
|
||||||
|
|
||||||
|
*curTile++ = tile; /* save in case we're checking phonies */
|
||||||
|
|
||||||
|
if ( !!stream || !!mainWord ) {
|
||||||
|
wordScoreFormatterAddTile( &fmtr, tile, tileMultiplier,
|
||||||
|
isBlank );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( isBlank ) {
|
||||||
|
tile = dict_getBlankTile( dict );
|
||||||
|
}
|
||||||
|
tileScore = dict_getTileValue( dict, tile );
|
||||||
|
|
||||||
|
/* The first tile in the move is already accounted for in
|
||||||
|
thisTileValue, so skip it here. */
|
||||||
|
if ( *incr != firstCoord ) {
|
||||||
|
restScore += tileScore * tileMultiplier;
|
||||||
|
}
|
||||||
|
} /* for each tile */
|
||||||
|
|
||||||
|
if ( !!notifyInfo ) {
|
||||||
|
XP_U16 len = curTile - checkWordBuf;
|
||||||
|
XP_Bool legal = engine_check( dict, checkWordBuf, len );
|
||||||
|
|
||||||
|
if ( !legal ) {
|
||||||
|
XP_UCHAR buf[(MAX_ROWS*2)+1];
|
||||||
|
dict_tilesToString( dict, checkWordBuf, len, buf );
|
||||||
|
(*notifyInfo->proc)( buf, notifyInfo->closure );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*curTile++ = tile; /* save in case we're checking phonies */
|
|
||||||
|
|
||||||
if ( !!stream || !!mainWord ) {
|
if ( !!stream || !!mainWord ) {
|
||||||
wordScoreFormatterAddTile( &fmtr, tile, tileMultiplier,
|
wordScoreFormatterFinish( &fmtr, checkWordBuf, stream,
|
||||||
isBlank );
|
mainWord );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( isBlank ) {
|
|
||||||
tile = dict_getBlankTile( dict );
|
|
||||||
}
|
|
||||||
tileScore = dict_getTileValue( dict, tile );
|
|
||||||
|
|
||||||
/* The first tile in the move is already accounted for in
|
|
||||||
thisTileValue, so skip it here. */
|
|
||||||
if ( *incr != firstCoord ) {
|
|
||||||
restScore += tileScore * tileMultiplier;
|
|
||||||
}
|
|
||||||
} /* for each tile */
|
|
||||||
|
|
||||||
if ( !!notifyInfo ) {
|
|
||||||
XP_U16 len = curTile - checkWordBuf;
|
|
||||||
XP_Bool legal = engine_check( dict, checkWordBuf, len );
|
|
||||||
|
|
||||||
if ( !legal ) {
|
|
||||||
XP_UCHAR buf[(MAX_ROWS*2)+1];
|
|
||||||
dict_tilesToString( dict, checkWordBuf, len, buf );
|
|
||||||
(*notifyInfo->proc)( buf, notifyInfo->closure );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !!stream || !!mainWord ) {
|
|
||||||
wordScoreFormatterFinish( &fmtr, checkWordBuf, stream, mainWord );
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
||||||
} else if ( engine != NULL ) {
|
} else if ( engine != NULL ) {
|
||||||
#else
|
#else
|
||||||
} else { /* non-debug case we know it's non-null */
|
} else { /* non-debug case we know it's non-null */
|
||||||
#endif
|
#endif
|
||||||
XP_ASSERT( nTiles==1 );
|
XP_ASSERT( nTiles==1 );
|
||||||
XP_ASSERT( engine_getScoreCache( engine, movei->commonCoord )
|
XP_ASSERT( engine_getScoreCache( engine, movei->commonCoord )
|
||||||
== restScore );
|
== restScore );
|
||||||
restScore = engine_getScoreCache( engine, movei->commonCoord );
|
restScore = engine_getScoreCache( engine, movei->commonCoord );
|
||||||
|
}
|
||||||
|
|
||||||
|
restScore += thisTileValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (restScore + thisTileValue);
|
return restScore;
|
||||||
} /* scoreWord */
|
} /* scoreWord */
|
||||||
|
|
||||||
static XP_U16
|
static XP_U16
|
||||||
|
|
Loading…
Add table
Reference in a new issue