diff --git a/xwords4/common/board.c b/xwords4/common/board.c index cc06bb354..decf444f6 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -2180,7 +2180,7 @@ board_requestHint( BoardCtxt* board, # endif #endif searchComplete = - engine_findMove( engine, model, selPlayer, + engine_findMove( engine, model, selPlayer, XP_FALSE, tiles, nTiles, usePrev, #ifdef XWFEATURE_BONUSALL allTilesBonus, diff --git a/xwords4/common/engine.c b/xwords4/common/engine.c index b0b9c99be..71cda9104 100644 --- a/xwords4/common/engine.c +++ b/xwords4/common/engine.c @@ -81,7 +81,7 @@ struct EngineCtxt { const ModelCtxt* model; const DictionaryCtxt* dict; XW_UtilCtxt* util; - XP_U16 turn; + XP_S16 turn; Engine_rack rack; Tile blankTile; @@ -96,6 +96,7 @@ struct EngineCtxt { XP_U16 star_row; XP_Bool returnNOW; XP_Bool isRobot; + XP_Bool includePending; MoveIterationData miData; XP_S16 blankValues[MAX_TRAY_TILES]; @@ -374,9 +375,9 @@ normalizeIQ( EngineCtxt* engine, XP_U16 iq ) * filled in in *newMove. */ XP_Bool -engine_findMove( EngineCtxt* engine, const ModelCtxt* model, - XP_U16 turn, const Tile* tiles, - const XP_U16 nTiles, XP_Bool usePrev, +engine_findMove( EngineCtxt* engine, const ModelCtxt* model, + XP_S16 turn, XP_Bool includePending, + const Tile* tiles, const XP_U16 nTiles, XP_Bool usePrev, #ifdef XWFEATURE_BONUSALL XP_U16 allTilesBonus, #endif @@ -427,6 +428,7 @@ engine_findMove( EngineCtxt* engine, const ModelCtxt* model, engine->model = model; engine->dict = model_getPlayerDict( model, turn ); engine->turn = turn; + engine->includePending = includePending; engine->usePrev = usePrev; engine->blankTile = dict_getBlankTile( engine->dict ); engine->returnNOW = XP_FALSE; @@ -763,9 +765,8 @@ localGetBoardTile( EngineCtxt* engine, XP_U16 col, XP_U16 row, row = tmp; } - if ( model_getTile( engine->model, col, row, XP_FALSE, - 0, /* don't get pending, so turn doesn't matter */ - &result, &isBlank, NULL, NULL ) ) { + if ( model_getTile( engine->model, col, row, engine->includePending, + engine->turn, &result, &isBlank, NULL, NULL ) ) { if ( isBlank && substBlank ) { result = engine->blankTile; } diff --git a/xwords4/common/engine.h b/xwords4/common/engine.h index 865910614..639163eed 100644 --- a/xwords4/common/engine.h +++ b/xwords4/common/engine.h @@ -49,8 +49,8 @@ void engine_reset( EngineCtxt* ctxt ); 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, + XP_S16 turn, XP_Bool includePending, + const Tile* tiles, XP_U16 nTiles, XP_Bool usePrev, #ifdef XWFEATURE_BONUSALL XP_U16 allTilesBonus, #endif diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 277c04ec1..289a5f361 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -580,9 +580,12 @@ model_getDictionary( const ModelCtxt* model ) } /* model_getDictionary */ DictionaryCtxt* -model_getPlayerDict( const ModelCtxt* model, XP_U16 playerNum ) +model_getPlayerDict( const ModelCtxt* model, XP_S16 playerNum ) { - DictionaryCtxt* dict = model->vol.dicts.dicts[playerNum]; + DictionaryCtxt* dict = NULL; + if ( 0 <= playerNum && playerNum < VSIZE(model->vol.dicts.dicts) ) { + dict = model->vol.dicts.dicts[playerNum]; + } if ( NULL == dict ) { dict = model->vol.dict; } diff --git a/xwords4/common/model.h b/xwords4/common/model.h index bab6c6a4f..588e57102 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -129,7 +129,7 @@ void model_setDictionary( ModelCtxt* model, DictionaryCtxt* dict ); DictionaryCtxt* model_getDictionary( const ModelCtxt* model ); void model_setPlayerDicts( ModelCtxt* model, const PlayerDicts* dicts ); -DictionaryCtxt* model_getPlayerDict( const ModelCtxt* model, XP_U16 playerNum ); +DictionaryCtxt* model_getPlayerDict( const ModelCtxt* model, XP_S16 playerNum ); XP_Bool model_getTile( const ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool getPending, XP_S16 turn, diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 85ca767ee..1e7b79979 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -882,7 +882,7 @@ makeRobotMove( ServerCtxt* server ) #endif XP_ASSERT( !!server_getEngineFor( server, turn ) ); searchComplete = engine_findMove( server_getEngineFor( server, turn ), - model, turn, tileSet->tiles, + model, turn, XP_FALSE, tileSet->tiles, tileSet->nTiles, XP_FALSE, #ifdef XWFEATURE_BONUSALL allTilesBonus,