modify engine score ranking to include estimate of bonus to be earned

if all tiles are used (ending the game and triggering penalties for
other players.)  Changes are protected by compile-time flags currently
not turned on.
This commit is contained in:
Eric House 2012-07-29 08:35:08 -07:00
parent 730cd0d599
commit 8f04bfadaf
5 changed files with 71 additions and 5 deletions

View file

@ -1798,10 +1798,22 @@ board_requestHint( BoardCtxt* board,
flipLimits( lp ); flipLimits( lp );
} }
} }
#endif
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus = 0;
# ifdef XWFEATURE_BONUSALLHINT
if ( 0 == pti->dividerLoc ) {
allTilesBonus = server_figureFinishBonus( board->server,
selPlayer );
}
# endif
#endif #endif
searchComplete = searchComplete =
engine_findMove( engine, model, selPlayer, engine_findMove( engine, model, selPlayer,
tiles, nTiles, usePrev, tiles, nTiles, usePrev,
#ifdef XWFEATURE_BONUSALL
allTilesBonus,
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
lp, useTileLimits, lp, useTileLimits,
#endif #endif

View file

@ -104,6 +104,9 @@ struct EngineCtxt {
XP_U16 scoreCache[MAX_ROWS]; XP_U16 scoreCache[MAX_ROWS];
XP_U16 nTilesMax; XP_U16 nTilesMax;
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus;
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
XP_U16 nTilesMin; XP_U16 nTilesMin;
XP_U16 nTilesMinUser, nTilesMaxUser; XP_U16 nTilesMinUser, nTilesMaxUser;
@ -242,11 +245,10 @@ static XP_Bool
initTray( EngineCtxt* engine, const Tile* tiles, XP_U16 numTiles ) initTray( EngineCtxt* engine, const Tile* tiles, XP_U16 numTiles )
{ {
XP_Bool result = numTiles > 0; XP_Bool result = numTiles > 0;
XP_U16 i;
if ( result ) { if ( result ) {
XP_MEMSET( engine->rack, 0, sizeof(engine->rack) ); XP_MEMSET( engine->rack, 0, sizeof(engine->rack) );
for ( i = 0; i < numTiles; ++i ) { while ( 0 < numTiles-- ) {
Tile tile = *tiles++; Tile tile = *tiles++;
XP_ASSERT( tile < MAX_UNIQUE_TILES ); XP_ASSERT( tile < MAX_UNIQUE_TILES );
++engine->rack[tile]; ++engine->rack[tile];
@ -380,6 +382,9 @@ XP_Bool
engine_findMove( EngineCtxt* engine, const ModelCtxt* model, engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
XP_U16 turn, const Tile* tiles, XP_U16 turn, const Tile* tiles,
XP_U16 nTiles, XP_Bool usePrev, XP_U16 nTiles, XP_Bool usePrev,
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus,
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
const BdHintLimits* searchLimits, const BdHintLimits* searchLimits,
XP_Bool useTileLimits, XP_Bool useTileLimits,
@ -389,7 +394,10 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
XP_Bool result = XP_TRUE; XP_Bool result = XP_TRUE;
XP_U16 star_row; XP_U16 star_row;
engine->nTilesMax = MAX_TRAY_TILES; engine->nTilesMax = XP_MIN( MAX_TRAY_TILES, nTiles );
#ifdef XWFEATURE_BONUSALL
engine->allTilesBonus = allTilesBonus;
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
if ( useTileLimits ) { if ( useTileLimits ) {
/* We'll want to use the numbers we've been using already unless /* We'll want to use the numbers we've been using already unless
@ -1092,7 +1100,13 @@ considerScoreWordHasBlanks( EngineCtxt* engine, XP_U16 blanksLeft,
&posmove->moveInfo, &posmove->moveInfo,
engine, (XWStreamCtxt*)NULL, engine, (XWStreamCtxt*)NULL,
(WordNotifierInfo*)NULL ); (WordNotifierInfo*)NULL );
#ifdef XWFEATURE_BONUSALL
if ( 0 != engine->allTilesBonus && 0 == engine->nTilesMax ) {
XP_LOGF( "%s: adding bonus: %d becoming %d", __func__, score ,
score + engine->allTilesBonus );
score += engine->allTilesBonus;
}
#endif
/* First, check that the score is even what we're interested in. If /* First, check that the score is even what we're interested in. If
it is, then go to the expense of filling in a PossibleMove to be it is, then go to the expense of filling in a PossibleMove to be
compared in full */ compared in full */

View file

@ -51,6 +51,9 @@ void engine_destroy( EngineCtxt* ctxt );
XP_Bool engine_findMove( EngineCtxt* ctxt, const ModelCtxt* model, XP_Bool engine_findMove( EngineCtxt* ctxt, const ModelCtxt* model,
XP_U16 turn, const Tile* tiles, XP_U16 turn, const Tile* tiles,
XP_U16 nTiles, XP_Bool usePrev, XP_U16 nTiles, XP_Bool usePrev,
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus,
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
const BdHintLimits* boardLimits, const BdHintLimits* boardLimits,
XP_Bool useTileLimits, XP_Bool useTileLimits,

View file

@ -811,11 +811,16 @@ makeRobotMove( ServerCtxt* server )
if ( !forceTrade ) { if ( !forceTrade ) {
tileSet = model_getPlayerTiles( model, turn ); tileSet = model_getPlayerTiles( model, turn );
#ifdef XWFEATURE_BONUSALL
XP_U16 allTilesBonus = server_figureFinishBonus( server, turn );
#endif
XP_ASSERT( !!server_getEngineFor( server, turn ) ); XP_ASSERT( !!server_getEngineFor( server, turn ) );
searchComplete = engine_findMove( server_getEngineFor( server, turn ), searchComplete = engine_findMove( server_getEngineFor( server, turn ),
model, turn, tileSet->tiles, model, turn, tileSet->tiles,
tileSet->nTiles, XP_FALSE, tileSet->nTiles, XP_FALSE,
#ifdef XWFEATURE_BONUSALL
allTilesBonus,
#endif
#ifdef XWFEATURE_SEARCHLIMIT #ifdef XWFEATURE_SEARCHLIMIT
NULL, XP_FALSE, NULL, XP_FALSE,
#endif #endif
@ -2851,6 +2856,34 @@ server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
} }
} /* server_formatRemainingTiles */ } /* server_formatRemainingTiles */
#ifdef XWFEATURE_BONUSALL
XP_U16
server_figureFinishBonus( const ServerCtxt* server, XP_U16 turn )
{
XP_U16 result = 0;
if ( 0 == pool_getNTilesLeft( server->pool ) ) {
XP_U16 nOthers = server->vol.gi->nPlayers - 1;
if ( 0 < nOthers ) {
Tile tile;
const DictionaryCtxt* dict = model_getDictionary( server->vol.model );
XP_U16 counts[dict_numTileFaces( dict )];
XP_MEMSET( counts, 0, sizeof(counts) );
model_countAllTrayTiles( server->vol.model, counts, turn );
for ( tile = 0; tile < VSIZE(counts); ++tile ) {
XP_U16 count = counts[tile];
if ( 0 < count ) {
result += count * dict_getTileValue( dict, tile );
}
}
/* Check this... */
result += result / nOthers;
}
}
// LOG_RETURNF( "%d", result );
return result;
}
#endif
#define IMPOSSIBLY_LOW_SCORE -1000 #define IMPOSSIBLY_LOW_SCORE -1000
void void
server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream ) server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )

View file

@ -126,6 +126,10 @@ void server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream ); void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream );
#ifdef XWFEATURE_BONUSALL
XP_U16 server_figureFinishBonus( const ServerCtxt* server, XP_U16 turn );
#endif
#ifdef CPLUS #ifdef CPLUS
} }
#endif #endif