don't let first player have unplayable rack

This commit is contained in:
Eric House 2021-01-09 20:36:52 -08:00
parent c20cd8c423
commit 8f30e4ef5a

View file

@ -168,7 +168,7 @@ static void setTurn( ServerCtxt* server, XWEnv xwe, XP_S16 turn );
static XWStreamCtxt* mkServerStream( ServerCtxt* server ); static XWStreamCtxt* mkServerStream( ServerCtxt* server );
static void fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum, static void fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum,
XP_U16 nToFetch, const TrayTileSet* tradedTiles, XP_U16 nToFetch, const TrayTileSet* tradedTiles,
TrayTileSet* resultTiles ); TrayTileSet* resultTiles, XP_Bool forceCanPlay );
static void finishMove( ServerCtxt* server, XWEnv xwe, static void finishMove( ServerCtxt* server, XWEnv xwe,
TrayTileSet* newTiles, XP_U16 turn ); TrayTileSet* newTiles, XP_U16 turn );
static XP_Bool dupe_checkTurns( ServerCtxt* server, XWEnv xwe ); static XP_Bool dupe_checkTurns( ServerCtxt* server, XWEnv xwe );
@ -1602,7 +1602,7 @@ server_tilesPicked( ServerCtxt* server, XWEnv xwe, XP_U16 player,
TrayTileSet newTiles = *newTilesP; TrayTileSet newTiles = *newTilesP;
pool_removeTiles( server->pool, &newTiles ); pool_removeTiles( server->pool, &newTiles );
fetchTiles( server, xwe, player, MAX_TRAY_TILES, NULL, &newTiles ); fetchTiles( server, xwe, player, MAX_TRAY_TILES, NULL, &newTiles, XP_FALSE );
XP_ASSERT( !inDuplicateMode(server) ); XP_ASSERT( !inDuplicateMode(server) );
model_assignPlayerTiles( server->vol.model, player, &newTiles ); model_assignPlayerTiles( server->vol.model, player, &newTiles );
@ -2438,7 +2438,8 @@ dupe_trayAllowsMoves( ServerCtxt* server, XWEnv xwe, XP_U16 turn,
*/ */
static void static void
fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum, XP_U16 nToFetch, fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum, XP_U16 nToFetch,
const TrayTileSet* tradedTiles, TrayTileSet* resultTiles ) const TrayTileSet* tradedTiles, TrayTileSet* resultTiles,
XP_Bool forceCanPlay /* First player shouldn't have unplayable rack*/ )
{ {
XP_ASSERT( server->vol.gi->serverRole != SERVER_ISCLIENT || !inDuplicateMode(server) ); XP_ASSERT( server->vol.gi->serverRole != SERVER_ISCLIENT || !inDuplicateMode(server) );
XP_Bool ask; XP_Bool ask;
@ -2515,7 +2516,7 @@ fetchTiles( ServerCtxt* server, XWEnv xwe, XP_U16 playerNum, XP_U16 nToFetch,
for ( XP_U16 nBadTrays = 0; 0 < nLeft; ) { for ( XP_U16 nBadTrays = 0; 0 < nLeft; ) {
pool_requestTiles( pool, &resultTiles->tiles[nSoFar], &nLeft ); pool_requestTiles( pool, &resultTiles->tiles[nSoFar], &nLeft );
if ( !inDuplicateMode( server ) ) { if ( !inDuplicateMode( server ) && !forceCanPlay ) {
break; break;
} else if ( dupe_trayAllowsMoves( server, xwe, playerNum, &resultTiles->tiles[0], } else if ( dupe_trayAllowsMoves( server, xwe, playerNum, &resultTiles->tiles[0],
nSoFar + nLeft ) nSoFar + nLeft )
@ -2583,7 +2584,7 @@ assignTilesToAll( ServerCtxt* server, XWEnv xwe )
} }
if ( 0 == ii || !gi->inDuplicateMode ) { if ( 0 == ii || !gi->inDuplicateMode ) {
newTiles.nTiles = 0; newTiles.nTiles = 0;
fetchTiles( server, xwe, ii, numAssigned, NULL, &newTiles ); fetchTiles( server, xwe, ii, numAssigned, NULL, &newTiles, ii == 0 );
} }
if ( gi->inDuplicateMode ) { if ( gi->inDuplicateMode ) {
@ -3201,7 +3202,7 @@ dupe_makeAndReportTrade( ServerCtxt* server, XWEnv xwe )
pool_replaceTiles( pool, &oldTiles ); pool_replaceTiles( pool, &oldTiles );
TrayTileSet newTiles = {0}; TrayTileSet newTiles = {0};
fetchTiles( server, xwe, DUP_PLAYER, oldTiles.nTiles, NULL, &newTiles ); fetchTiles( server, xwe, DUP_PLAYER, oldTiles.nTiles, NULL, &newTiles, XP_FALSE );
model_commitDupeTrade( model, &oldTiles, &newTiles ); model_commitDupeTrade( model, &oldTiles, &newTiles );
@ -3355,7 +3356,7 @@ dupe_commitAndReportMove( ServerCtxt* server, XWEnv xwe, XP_U16 winner,
model_currentMoveToMoveInfo( model, winner, &moveInfo ); model_currentMoveToMoveInfo( model, winner, &moveInfo );
TrayTileSet newTiles = {0}; TrayTileSet newTiles = {0};
fetchTiles( server, xwe, winner, nTiles, NULL, &newTiles ); fetchTiles( server, xwe, winner, nTiles, NULL, &newTiles, XP_FALSE );
for ( XP_U16 player = 0; player < nPlayers; ++player ) { for ( XP_U16 player = 0; player < nPlayers; ++player ) {
model_resetCurrentTurn( model, xwe, player ); model_resetCurrentTurn( model, xwe, player );
@ -3665,7 +3666,7 @@ finishMove( ServerCtxt* server, XWEnv xwe, TrayTileSet* newTiles, XP_U16 turn )
server->vol.pickTilesCalled[turn] = XP_FALSE; server->vol.pickTilesCalled[turn] = XP_FALSE;
XP_U16 nTilesMoved = model_getCurrentMoveCount( model, turn ); XP_U16 nTilesMoved = model_getCurrentMoveCount( model, turn );
fetchTiles( server, xwe, turn, nTilesMoved, NULL, newTiles ); fetchTiles( server, xwe, turn, nTilesMoved, NULL, newTiles, XP_FALSE );
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT; XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
XP_Bool isLegalMove = XP_TRUE; XP_Bool isLegalMove = XP_TRUE;
@ -3718,7 +3719,7 @@ server_commitTrade( ServerCtxt* server, XWEnv xwe, const TrayTileSet* oldTiles,
} }
XP_U16 turn = server->nv.currentTurn; XP_U16 turn = server->nv.currentTurn;
fetchTiles( server, xwe, turn, oldTiles->nTiles, oldTiles, &newTiles ); fetchTiles( server, xwe, turn, oldTiles->nTiles, oldTiles, &newTiles, XP_FALSE );
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
if ( server->vol.gi->serverRole == SERVER_ISCLIENT ) { if ( server->vol.gi->serverRole == SERVER_ISCLIENT ) {