mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-15 15:41:24 +01:00
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:
parent
730cd0d599
commit
8f04bfadaf
5 changed files with 71 additions and 5 deletions
|
@ -1798,10 +1798,22 @@ board_requestHint( BoardCtxt* board,
|
|||
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
|
||||
searchComplete =
|
||||
engine_findMove( engine, model, selPlayer,
|
||||
tiles, nTiles, usePrev,
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
allTilesBonus,
|
||||
#endif
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
lp, useTileLimits,
|
||||
#endif
|
||||
|
|
|
@ -104,6 +104,9 @@ struct EngineCtxt {
|
|||
XP_U16 scoreCache[MAX_ROWS];
|
||||
|
||||
XP_U16 nTilesMax;
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
XP_U16 allTilesBonus;
|
||||
#endif
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
XP_U16 nTilesMin;
|
||||
XP_U16 nTilesMinUser, nTilesMaxUser;
|
||||
|
@ -242,11 +245,10 @@ static XP_Bool
|
|||
initTray( EngineCtxt* engine, const Tile* tiles, XP_U16 numTiles )
|
||||
{
|
||||
XP_Bool result = numTiles > 0;
|
||||
XP_U16 i;
|
||||
|
||||
if ( result ) {
|
||||
XP_MEMSET( engine->rack, 0, sizeof(engine->rack) );
|
||||
for ( i = 0; i < numTiles; ++i ) {
|
||||
while ( 0 < numTiles-- ) {
|
||||
Tile tile = *tiles++;
|
||||
XP_ASSERT( tile < MAX_UNIQUE_TILES );
|
||||
++engine->rack[tile];
|
||||
|
@ -380,6 +382,9 @@ XP_Bool
|
|||
engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
|
||||
XP_U16 turn, const Tile* tiles,
|
||||
XP_U16 nTiles, XP_Bool usePrev,
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
XP_U16 allTilesBonus,
|
||||
#endif
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
const BdHintLimits* searchLimits,
|
||||
XP_Bool useTileLimits,
|
||||
|
@ -389,7 +394,10 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
|
|||
XP_Bool result = XP_TRUE;
|
||||
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
|
||||
if ( useTileLimits ) {
|
||||
/* 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,
|
||||
engine, (XWStreamCtxt*)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
|
||||
it is, then go to the expense of filling in a PossibleMove to be
|
||||
compared in full */
|
||||
|
|
|
@ -51,6 +51,9 @@ void engine_destroy( EngineCtxt* ctxt );
|
|||
XP_Bool engine_findMove( EngineCtxt* ctxt, const ModelCtxt* model,
|
||||
XP_U16 turn, const Tile* tiles,
|
||||
XP_U16 nTiles, XP_Bool usePrev,
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
XP_U16 allTilesBonus,
|
||||
#endif
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
const BdHintLimits* boardLimits,
|
||||
XP_Bool useTileLimits,
|
||||
|
|
|
@ -811,11 +811,16 @@ makeRobotMove( ServerCtxt* server )
|
|||
|
||||
if ( !forceTrade ) {
|
||||
tileSet = model_getPlayerTiles( model, turn );
|
||||
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
XP_U16 allTilesBonus = server_figureFinishBonus( server, turn );
|
||||
#endif
|
||||
XP_ASSERT( !!server_getEngineFor( server, turn ) );
|
||||
searchComplete = engine_findMove( server_getEngineFor( server, turn ),
|
||||
model, turn, tileSet->tiles,
|
||||
tileSet->nTiles, XP_FALSE,
|
||||
#ifdef XWFEATURE_BONUSALL
|
||||
allTilesBonus,
|
||||
#endif
|
||||
#ifdef XWFEATURE_SEARCHLIMIT
|
||||
NULL, XP_FALSE,
|
||||
#endif
|
||||
|
@ -2851,6 +2856,34 @@ server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
|
|||
}
|
||||
} /* 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
|
||||
void
|
||||
server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream )
|
||||
|
|
|
@ -126,6 +126,10 @@ void server_formatRemainingTiles( 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
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue