From fec0124f8ca1af2f58586ee12c47fe42b0d16ac8 Mon Sep 17 00:00:00 2001 From: Eric House Date: Fri, 5 Apr 2019 11:54:58 -0700 Subject: [PATCH] allow long-tap lookup of pending words too When a word's been formed as part of the current turn, but not yet committed, allow long-tap to trigger an offer to look it up online same as for already-committed words. Allows checking the legality of potential plays AND figuring WTF the hint feature just suggested. --- xwords4/common/board.c | 53 ++++++++++++++++++++++------------------- xwords4/common/model.c | 13 ++++++++-- xwords4/common/model.h | 2 +- xwords4/common/modelp.h | 2 +- xwords4/common/mscore.c | 6 ++--- 5 files changed, 44 insertions(+), 32 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index d3f832c8c..cc06bb354 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1315,35 +1315,38 @@ timerFiredForPen( BoardCtxt* board ) #ifdef XWFEATURE_RAISETILE draw = dragDropSetAdd( board ); #endif - } else { - XP_Bool listWords = XP_FALSE; -#ifdef XWFEATURE_BOARDWORDS - XP_U16 modelCol, modelRow; - flipIf( board, col, row, &modelCol, &modelRow ); - listWords = model_getTile( board->model, modelCol, modelRow, - XP_TRUE, board->selPlayer, NULL, - NULL, NULL, NULL ); - if ( listWords ) { - XWStreamCtxt* stream = - mem_stream_make_raw( MPPARM(board->mpool) - dutil_getVTManager(board->dutil) ); - model_listWordsThrough( board->model, modelCol, modelRow, - stream ); - util_cellSquareHeld( board->util, stream ); - stream_destroy( stream ); - } + } + + /* We calculate words even for a pending tile set, meaning + dragDrop might be happening too. */ + XP_Bool listWords = XP_FALSE; +#ifdef XWFEATURE_BOARDWORDS /* here it is */ + XP_U16 modelCol, modelRow; + flipIf( board, col, row, &modelCol, &modelRow ); + listWords = model_getTile( board->model, modelCol, modelRow, + XP_TRUE, board->selPlayer, NULL, + NULL, NULL, NULL ); + if ( listWords ) { + XP_LOGF( "%s(): listWords came back true", __func__ ); + XWStreamCtxt* stream = + mem_stream_make_raw( MPPARM(board->mpool) + dutil_getVTManager(board->dutil) ); + model_listWordsThrough( board->model, modelCol, modelRow, + board->selPlayer, stream ); + util_cellSquareHeld( board->util, stream ); + stream_destroy( stream ); + } #endif - if ( !listWords ) { - XWBonusType bonus; - bonus = model_getSquareBonus( board->model, col, row ); - if ( bonus != BONUS_NONE ) { + if ( !listWords ) { + XWBonusType bonus; + bonus = model_getSquareBonus( board->model, col, row ); + if ( bonus != BONUS_NONE ) { #ifdef XWFEATURE_MINIWIN - text = draw_getMiniWText( board->draw, - (XWMiniTextType)bonus ); + text = draw_getMiniWText( board->draw, + (XWMiniTextType)bonus ); #else - util_bonusSquareHeld( board->util, bonus ); + util_bonusSquareHeld( board->util, bonus ); #endif - } } } board->penTimerFired = XP_TRUE; diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 1c6788e10..277c04ec1 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -1708,13 +1708,13 @@ commitTurn( ModelCtxt* model, XP_S16 turn, const TrayTileSet* newTiles, PlayerCtxt* player = &model->players[turn]; if ( useStack ) { - MoveInfo moveInfo = {0}; XP_Bool isHorizontal; #ifdef DEBUG XP_Bool inLine = #endif tilesInLine( model, turn, &isHorizontal ); XP_ASSERT( inLine ); + MoveInfo moveInfo = {0}; normalizeMoves( model, turn, isHorizontal, &moveInfo ); stack_addMove( model->vol.stack, turn, &moveInfo, newTiles ); @@ -2396,11 +2396,20 @@ listWordsThrough( const XP_UCHAR* word, XP_Bool XP_UNUSED(isLegal), * How? Undo backwards until we find the move that placed that tile.*/ void model_listWordsThrough( ModelCtxt* model, XP_U16 col, XP_U16 row, - XWStreamCtxt* stream ) + XP_S16 turn, XWStreamCtxt* stream ) { ModelCtxt* tmpModel = makeTmpModel( model, NULL, NULL, NULL, NULL ); copyStack( model, tmpModel->vol.stack, model->vol.stack ); + XP_Bool isHorizontal; + if ( tilesInLine( model, turn, &isHorizontal ) ) { + MoveInfo moveInfo = {0}; + normalizeMoves( model, turn, isHorizontal, &moveInfo ); + model_makeTurnFromMoveInfo( tmpModel, turn, &moveInfo ); + TrayTileSet newTiles = {0}; + commitTurn( tmpModel, turn, &newTiles, NULL, NULL, XP_TRUE ); + } + XP_ASSERT( !!stream ); StackCtxt* stack = tmpModel->vol.stack; XP_U16 nEntriesBefore = stack_getNEntries( stack ); diff --git a/xwords4/common/model.h b/xwords4/common/model.h index b48ca5a29..bab6c6a4f 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -282,7 +282,7 @@ XP_Bool model_getPlayersLastScore( ModelCtxt* model, XP_S16 player, LastMoveInfo* info ); #ifdef XWFEATURE_BOARDWORDS void model_listWordsThrough( ModelCtxt* model, XP_U16 col, XP_U16 row, - XWStreamCtxt* stream ); + XP_S16 turn, XWStreamCtxt* stream ); #endif /* Have there been too many passes (so game should end)? */ diff --git a/xwords4/common/modelp.h b/xwords4/common/modelp.h index e560e87b5..8a933372e 100644 --- a/xwords4/common/modelp.h +++ b/xwords4/common/modelp.h @@ -90,7 +90,7 @@ struct ModelCtxt { void invalidateScore( ModelCtxt* model, XP_S16 player ); XP_Bool tilesInLine( ModelCtxt* model, XP_S16 turn, XP_Bool* isHorizontal ); -void normalizeMoves( ModelCtxt* model, XP_S16 turn, +void normalizeMoves( const ModelCtxt* model, XP_S16 turn, XP_Bool isHorizontal, MoveInfo* moveInfo ); void adjustScoreForUndone( ModelCtxt* model, MoveInfo* mi, XP_U16 turn ); #ifdef CPLUS diff --git a/xwords4/common/mscore.c b/xwords4/common/mscore.c index 5132eb9d6..df6a27143 100644 --- a/xwords4/common/mscore.c +++ b/xwords4/common/mscore.c @@ -277,15 +277,15 @@ tilesInLine( ModelCtxt* model, XP_S16 turn, XP_Bool* isHorizontal ) } /* tilesInLine */ void -normalizeMoves( ModelCtxt* model, XP_S16 turn, XP_Bool isHorizontal, +normalizeMoves( const ModelCtxt* model, XP_S16 turn, XP_Bool isHorizontal, MoveInfo* moveInfo ) { XP_S16 lowCol, ii, jj, thisCol; /* unsigned is a problem on palm */ - PlayerCtxt* player = &model->players[turn]; + const PlayerCtxt* player = &model->players[turn]; XP_U16 nTiles = player->nPending; XP_S16 lastTaken; short lowIndex = 0; - PendingTile* pt; + const PendingTile* pt; moveInfo->isHorizontal = isHorizontal; moveInfo->nTiles = (XP_U8)nTiles;