From 0a696cf203908c8737d6f3fac3a9cd37d73766b1 Mon Sep 17 00:00:00 2001 From: Eric House Date: Sat, 28 Mar 2020 16:25:30 -0700 Subject: [PATCH] cleanup --- xwords4/common/board.c | 18 ------------- xwords4/common/comms.c | 6 +++++ xwords4/common/model.c | 23 +--------------- xwords4/common/model.h | 3 +-- xwords4/common/server.c | 41 +++++++++++++---------------- xwords4/common/smsproto.h | 2 +- xwords4/linux/scripts/discon_ok2.py | 2 +- 7 files changed, 29 insertions(+), 66 deletions(-) diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 343fa78af..e2c43609c 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -2125,24 +2125,6 @@ MIN_TRADE_TILES( const BoardCtxt* board ) return 6 == langCode ? 1 : MAX_TRAY_TILES; } -#ifdef DEBUG -/* static void */ -/* assertTilesInTiles( const BoardCtxt* board, const MoveInfo* mi, */ -/* const Tile* tiles, XP_U16 nTiles ) */ -/* { */ -/* Tile blank = dict_getBlankTile( model_getDictionary( board->model ) ); */ -/* for ( XP_U16 ii = 0; ii < mi->nTiles; ++ii ) { */ -/* Tile tile = mi->tiles[ii].tile; */ -/* XP_Bool found = XP_FALSE; */ -/* for ( XP_U16 jj = 0; !found && jj < nTiles; ++jj ) { */ -/* found = tiles[jj] == tile */ -/* || (tiles[jj] == blank && IS_BLANK(tile)); */ -/* } */ -/* XP_ASSERT( found ); */ -/* } */ -/* } */ -#endif - /* Refuse with error message if any tiles are currently on board in this turn. * Then call the engine, and display the first move. Return true if there's * any redrawing to be done. diff --git a/xwords4/common/comms.c b/xwords4/common/comms.c index 248862de9..464d09f3c 100644 --- a/xwords4/common/comms.c +++ b/xwords4/common/comms.c @@ -2316,6 +2316,12 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream, /* XP_LOGF( "%s: not expecting %s messages", __func__, */ /* ConnType2Str( addrType ) ); */ } else { +#ifdef DEBUG + if (0 == (comms->addr._conTypes & retAddr->_conTypes)) { + XP_LOGFF( "not expecting %s messages (but proceeding)", + ConnType2Str( addrType ) ); + } +#endif XWHostID senderID = 0; /* unset; default for non-relay cases */ XP_Bool usingRelay = XP_FALSE; diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 8b2711905..36fa2ea46 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -1436,28 +1436,7 @@ model_removePlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index ) } /* model_removePlayerTile */ void -model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const MoveInfo* mi ) -{ - XP_ASSERT( turn >= 0 ); - PlayerCtxt* player = &model->players[turn]; - for ( XP_U16 ii = 0; ii < mi->nTiles; ++ii ) { - Tile tile = mi->tiles[ii].tile; - if ( IS_BLANK( tile ) ) { - tile = dict_getBlankTile( model_getDictionary(model) ); - } - XP_S16 index = -1; - for ( XP_U16 jj = 0; index < 0 && jj < player->trayTiles.nTiles; ++jj ) { - if ( tile == player->trayTiles.tiles[jj] ) { - index = jj; - } - } - XP_ASSERT( index >= 0 ); - model_removePlayerTile( model, turn, index ); - } -} - -void -model_removePlayerTiles2( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles ) +model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles ) { XP_ASSERT( turn >= 0 ); PlayerCtxt* player = &model->players[turn]; diff --git a/xwords4/common/model.h b/xwords4/common/model.h index 799738bdb..ebfe71a30 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -152,8 +152,7 @@ void model_assignDupeTiles( ModelCtxt* model, const TrayTileSet* tiles ); Tile model_getPlayerTile( const ModelCtxt* model, XP_S16 turn, XP_S16 index ); Tile model_removePlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index ); -void model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const MoveInfo* mi ); -void model_removePlayerTiles2( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles ); +void model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles ); void model_addPlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index, Tile tile ); void model_moveTileOnTray( ModelCtxt* model, XP_S16 turn, XP_S16 indexCur, diff --git a/xwords4/common/server.c b/xwords4/common/server.c index a0a2cb72b..3ab9cbddc 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -48,10 +48,10 @@ enum { }; typedef XP_U8 GameEndReason; -typedef enum {DUPE_STUFF_TRADES_SERVER, - DUPE_STUFF_MOVES_SERVER, - DUPE_STUFF_MOVE_CLIENT, - DUPE_STUFF_PAUSE, +typedef enum { DUPE_STUFF_TRADES_SERVER, + DUPE_STUFF_MOVES_SERVER, + DUPE_STUFF_MOVE_CLIENT, + DUPE_STUFF_PAUSE, } DUPE_STUFF; typedef struct ServerPlayer { @@ -140,7 +140,7 @@ struct ServerCtxt { # define ROBOTWAITING(s) XP_FALSE #endif -# define dupTimerRunning() server_canPause(server) +# define dupe_timerRunning() server_canPause(server) #define NPASSES_OK(s) model_recentPassCountOk((s)->vol.model) @@ -1141,7 +1141,7 @@ server_pause( ServerCtxt* server, XP_S16 turn, const XP_UCHAR* msg ) } static void -autoPause( ServerCtxt* server ) +dupe_autoPause( ServerCtxt* server ) { XP_LOGF( "%s()", __func__ ); @@ -1214,7 +1214,7 @@ dupe_handleServerTrade( ServerCtxt* server, XWStreamCtxt* stream ) ModelCtxt* model = server->vol.model; model_resetCurrentTurn( model, DUP_PLAYER ); - model_removePlayerTiles2( model, DUP_PLAYER, &oldTiles ); + model_removePlayerTiles( model, DUP_PLAYER, &oldTiles ); pool_replaceTiles( server->pool, &oldTiles ); pool_removeTiles( server->pool, &newTiles ); @@ -2969,7 +2969,7 @@ reflectMove( ServerCtxt* server, XWStreamCtxt* stream ) #endif /* XWFEATURE_STANDALONE_ONLY */ static void -chooseMove( const ServerCtxt* server, XP_U16 nPlayers, XP_U16 scores[], +dupe_chooseMove( const ServerCtxt* server, XP_U16 nPlayers, XP_U16 scores[], XP_U16* winner, XP_U16* winningNTiles ) { ModelCtxt* model = server->vol.model; @@ -3018,7 +3018,7 @@ chooseMove( const ServerCtxt* server, XP_U16 nPlayers, XP_U16 scores[], } - const XP_U16 winnerIndx = XP_RANDOM() % nWinners; + const XP_U16 winnerIndx = 1 == nWinners ? 0 : XP_RANDOM() % nWinners; *winner = moveData[winnerIndx].player; *winningNTiles = moveData[winnerIndx].nTiles; /* This fires: I need the reassign-no-moves thing */ @@ -3031,7 +3031,7 @@ chooseMove( const ServerCtxt* server, XP_U16 nPlayers, XP_U16 scores[], } static XP_Bool -allForced( const ServerCtxt* server ) +dupe_allForced( const ServerCtxt* server ) { XP_Bool result = XP_TRUE; for ( XP_U16 ii = 0; result && ii < server->vol.gi->nPlayers; ++ii ) { @@ -3052,14 +3052,14 @@ dupe_commitAndReport( ServerCtxt* server ) XP_U16 winner; XP_U16 nTiles; - chooseMove( server, nPlayers, scores, &winner, &nTiles ); + dupe_chooseMove( server, nPlayers, scores, &winner, &nTiles ); /* If nobody can move AND there are tiles left, trade instead of recording a 0. Unless we're running a timer, in which case it's most likely noboby's playing, so pause the game instead. */ if ( 0 == scores[winner] && 0 < pool_getNTilesLeft(server->pool) ) { - if ( dupTimerRunning() && allForced( server ) ) { - autoPause( server ); + if ( dupe_timerRunning() && dupe_allForced( server ) ) { + dupe_autoPause( server ); } else { dupe_makeAndReportTrade( server ); } @@ -3095,7 +3095,7 @@ dupe_makeAndReportTrade( ServerCtxt* server ) model_resetCurrentTurn( model, DUP_PLAYER ); TrayTileSet oldTiles = *model_getPlayerTiles( model, DUP_PLAYER ); - model_removePlayerTiles2( model, DUP_PLAYER, &oldTiles ); + model_removePlayerTiles( model, DUP_PLAYER, &oldTiles ); pool_replaceTiles( pool, &oldTiles ); TrayTileSet newTiles = {0}; @@ -3215,7 +3215,7 @@ dupe_receivePause( ServerCtxt* server, XWStreamCtxt* stream ) } static XP_Bool -handleDupeStuff( ServerCtxt* server, XWStreamCtxt* stream ) +dupe_handleStuff( ServerCtxt* server, XWStreamCtxt* stream ) { XP_Bool accepted; XP_Bool isServer = amServer( server ); @@ -3293,7 +3293,7 @@ dupe_commitAndReportMove( ServerCtxt* server, XP_U16 winner, static void dupe_forceCommits( ServerCtxt* server ) { - if ( dupTimerRunning() ) { + if ( dupe_timerRunning() ) { XP_U32 now = dutil_getCurSeconds( server->vol.dutil ); if ( server->nv.dupTimerExpires <= now ) { @@ -3316,7 +3316,7 @@ dupe_forceCommits( ServerCtxt* server ) guest, I care only about local players. If I'm a host or standalone, I care about everything. */ static void -checkWhatsDone( const ServerCtxt* server, XP_Bool amServer, +dupe_checkWhatsDone( const ServerCtxt* server, XP_Bool amServer, XP_Bool* allDoneP, XP_Bool* allLocalsDoneP ) { XP_Bool allDone = XP_TRUE; @@ -3355,7 +3355,7 @@ dupe_checkTurns( ServerCtxt* server ) XP_Bool allLocalsDone = XP_TRUE; XP_Bool amServer = server->vol.gi->serverRole == SERVER_ISSERVER || server->vol.gi->serverRole == SERVER_STANDALONE; - checkWhatsDone( server, amServer, &allDone, &allLocalsDone ); + dupe_checkWhatsDone( server, amServer, &allDone, &allLocalsDone ); XP_LOGF( "%s(): allDone: %d", __func__, allDone ); @@ -3604,9 +3604,6 @@ finishMove( ServerCtxt* server, TrayTileSet* newTiles, XP_U16 turn ) model_getNumTilesInTray( model, turn ) ); } /* finishMove */ -/* return XP_TRUE; */ -/* } /\* server_commitMove *\/ */ - XP_Bool server_commitTrade( ServerCtxt* server, const TrayTileSet* oldTiles, TrayTileSet* newTilesP ) @@ -4146,7 +4143,7 @@ server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming ) } break; case XWPROTO_DUPE_STUFF: - accepted = handleDupeStuff( server, incoming ); + accepted = dupe_handleStuff( server, incoming ); break; default: XP_WARNF( "%s: Unknown code on incoming message: %d\n", diff --git a/xwords4/common/smsproto.h b/xwords4/common/smsproto.h index 3960b08b9..e621121af 100644 --- a/xwords4/common/smsproto.h +++ b/xwords4/common/smsproto.h @@ -105,6 +105,6 @@ void smsproto_freeMsgArray( SMSProto* state, SMSMsgArray* arr ); # ifdef DEBUG void smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil ); # else -# define smsproto_runTests( p1, p2 ) +# define smsproto_runTests( p1, p2 ) # endif #endif diff --git a/xwords4/linux/scripts/discon_ok2.py b/xwords4/linux/scripts/discon_ok2.py index b0ef17b00..cbd9bbd82 100755 --- a/xwords4/linux/scripts/discon_ok2.py +++ b/xwords4/linux/scripts/discon_ok2.py @@ -694,7 +694,7 @@ def mkParser(): parser.add_argument('--use-gtk', dest = 'USE_GTK', default = False, action = 'store_true', help = 'run games using gtk instead of ncurses') - parser.add_argument('--duplicate-pct', dest = 'DUP_PCT', default = 0, type = int, + parser.add_argument('--duplicate-pct', dest = 'DUP_PCT', default = 50, type = int, help = 'this fraction played in duplicate mode') # #