From 2d6ce6cfdaa8e71b4166774ba10e498ab7f99122 Mon Sep 17 00:00:00 2001 From: Eric House Date: Thu, 20 Jan 2022 22:07:58 -0800 Subject: [PATCH] fix problems with tile picking introduced by 9-tiles Not sure if these would show up if you're not picking face-up, but if so they justify a release. --- xwords4/common/board.c | 4 ++-- xwords4/common/server.c | 16 +++++++++------- xwords4/linux/gtkboard.c | 7 ++++--- xwords4/linux/gtkletterask.c | 7 ++++--- xwords4/linux/gtkletterask.h | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 1ae3853ad..a11ae3e45 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1156,8 +1156,8 @@ board_commitTurn( BoardCtxt* board, XWEnv xwe, XP_Bool phoniesConfirmed, } if ( board->skipCommitConfirm || turnConfirmed ) { - XP_U16 nToPick = MAX_TRAY_TILES - - model_getNumTilesInTray( model, selPlayer ); + XP_U16 nToPick = board->gi->traySize + - model_getNumTilesInTray( model, selPlayer ); if ( !server_askPickTiles( board->server, xwe, selPlayer, newTiles, nToPick ) ) { result = server_commitMove( board->server, xwe, selPlayer, diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 32673139b..2b6660029 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -1419,7 +1419,7 @@ makeRobotMove( ServerCtxt* server, XWEnv xwe ) #ifdef XWFEATURE_SLOW_ROBOT if ( 0 != server->nv.robotTradePct ) { XP_ASSERT( ! inDuplicateMode( server ) ); - if ( server_countTilesInPool( server ) >= MAX_TRAY_TILES ) { + if ( server_countTilesInPool( server ) >= gi->traySize ) { XP_U16 pct = XP_RANDOM() % 100; forceTrade = pct < server->nv.robotTradePct ; } @@ -1459,7 +1459,7 @@ makeRobotMove( ServerCtxt* server, XWEnv xwe ) XP_Bool trade = forceTrade || ((newMove.nTiles == 0) && !canMove && - (server_countTilesInPool( server ) >= MAX_TRAY_TILES)); + (server_countTilesInPool( server ) >= gi->traySize)); server->vol.showPrevMove = XP_TRUE; if ( inDuplicateMode(server) || server->nv.showRobotScores ) { @@ -1640,7 +1640,8 @@ server_tilesPicked( ServerCtxt* server, XWEnv xwe, XP_U16 player, TrayTileSet newTiles = *newTilesP; pool_removeTiles( server->pool, &newTiles ); - fetchTiles( server, xwe, player, MAX_TRAY_TILES, NULL, &newTiles, XP_FALSE ); + fetchTiles( server, xwe, player, server->vol.gi->traySize, + NULL, &newTiles, XP_FALSE ); XP_ASSERT( !inDuplicateMode(server) ); model_assignPlayerTiles( server->vol.model, player, &newTiles ); @@ -2476,15 +2477,16 @@ fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum, XP_U16 nToFetch, XP_Bool ask; XP_U16 nSoFar = resultTiles->nTiles; PoolContext* pool = server->pool; - const XP_UCHAR* curTray[MAX_TRAY_TILES]; + const CurGameInfo* gi = server->vol.gi; + const XP_UCHAR* curTray[gi->traySize]; #ifdef FEATURE_TRAY_EDIT const DictionaryCtxt* dict = model_getDictionary( server->vol.model ); #endif XP_ASSERT( !!pool ); #ifdef FEATURE_TRAY_EDIT - ask = server->vol.gi->allowPickTiles - && !LP_IS_ROBOT(&server->vol.gi->players[playerNum]); + ask = gi->allowPickTiles + && !LP_IS_ROBOT(&gi->players[playerNum]); #else ask = XP_FALSE; #endif @@ -2609,7 +2611,7 @@ assignTilesToAll( ServerCtxt* server, XWEnv xwe ) if ( 0 == model_getNumTilesInTray( model, ii ) ) { if ( pickingTiles && !LP_IS_ROBOT(&gi->players[ii]) && informNeedPickTiles( server, xwe, XP_TRUE, ii, - MAX_TRAY_TILES ) ) { + gi->traySize ) ) { allDone = XP_FALSE; break; } diff --git a/xwords4/linux/gtkboard.c b/xwords4/linux/gtkboard.c index f854f82be..baedafd1f 100644 --- a/xwords4/linux/gtkboard.c +++ b/xwords4/linux/gtkboard.c @@ -1575,7 +1575,7 @@ ask_blank( gpointer data ) CommonGlobals* cGlobals = &globals->cGlobals; XP_UCHAR* name = globals->cGlobals.gi->players[cGlobals->selPlayer].name; - XP_S16 result = gtkletterask( NULL, XP_FALSE, name, + XP_S16 result = gtkletterask( NULL, XP_FALSE, name, 1, cGlobals->nTiles, cGlobals->tiles, NULL ); for ( int ii = 0; ii < cGlobals->nTiles; ++ii ) { @@ -1591,6 +1591,7 @@ ask_blank( gpointer data ) return 0; } + static void gtk_util_notifyPickTileBlank( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe), XP_U16 playerNum, XP_U16 col, @@ -1619,8 +1620,8 @@ ask_tiles( gpointer data ) XP_UCHAR* name = cGlobals->gi->players[cGlobals->selPlayer].name; for ( XP_Bool done = XP_FALSE; !done; ) { XP_S16 picked = gtkletterask( &newTiles, XP_TRUE, name, - cGlobals->nTiles, cGlobals->tiles, - cGlobals->tileCounts ); + cGlobals->nToPick, cGlobals->nTiles, + cGlobals->tiles, cGlobals->tileCounts ); switch ( picked ) { case PICKER_PICKALL: done = XP_TRUE; diff --git a/xwords4/linux/gtkletterask.c b/xwords4/linux/gtkletterask.c index 14c2b6354..60a0848b1 100644 --- a/xwords4/linux/gtkletterask.c +++ b/xwords4/linux/gtkletterask.c @@ -46,7 +46,8 @@ abort_button_event( GtkWidget* widget, gpointer XP_UNUSED(closure) ) XP_S16 gtkletterask( const TrayTileSet* curPick, XP_Bool forTray, const XP_UCHAR* name, - XP_U16 nTiles, const XP_UCHAR** texts, const XP_U16* counts ) + XP_U16 nToPick, XP_U16 nTiles, const XP_UCHAR** texts, + const XP_U16* counts ) { GtkWidget* dialog; GtkWidget* label; @@ -102,8 +103,8 @@ gtkletterask( const TrayTileSet* curPick, XP_Bool forTray, const XP_UCHAR* name, gtk_window_set_modal( GTK_WINDOW( dialog ), TRUE ); if ( forTray ) { - char* fmt = "Choose a tile for %s."; - XP_SNPRINTF( buf, sizeof(buf), fmt, name ); + char* fmt = "Choose %d tiles for %s."; + XP_SNPRINTF( buf, sizeof(buf), fmt, nToPick, name ); txt = buf; } else { txt = "Choose a letter for your blank."; diff --git a/xwords4/linux/gtkletterask.h b/xwords4/linux/gtkletterask.h index a875f8f7e..997bacb7b 100644 --- a/xwords4/linux/gtkletterask.h +++ b/xwords4/linux/gtkletterask.h @@ -27,7 +27,7 @@ #include "gtkboard.h" XP_S16 gtkletterask( const TrayTileSet* curPick, XP_Bool forTray, - const XP_UCHAR* name, + const XP_UCHAR* name, XP_U16 nToPick, XP_U16 nTiles, const XP_UCHAR** texts, const XP_U16* counts );