mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-04 23:02:02 +01:00
cleanup
This commit is contained in:
parent
0f6b1897b7
commit
0a696cf203
7 changed files with 29 additions and 66 deletions
|
@ -2125,24 +2125,6 @@ MIN_TRADE_TILES( const BoardCtxt* board )
|
||||||
return 6 == langCode ? 1 : MAX_TRAY_TILES;
|
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.
|
/* 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
|
* Then call the engine, and display the first move. Return true if there's
|
||||||
* any redrawing to be done.
|
* any redrawing to be done.
|
||||||
|
|
|
@ -2316,6 +2316,12 @@ comms_checkIncomingStream( CommsCtxt* comms, XWStreamCtxt* stream,
|
||||||
/* XP_LOGF( "%s: not expecting %s messages", __func__, */
|
/* XP_LOGF( "%s: not expecting %s messages", __func__, */
|
||||||
/* ConnType2Str( addrType ) ); */
|
/* ConnType2Str( addrType ) ); */
|
||||||
} else {
|
} 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 */
|
XWHostID senderID = 0; /* unset; default for non-relay cases */
|
||||||
XP_Bool usingRelay = XP_FALSE;
|
XP_Bool usingRelay = XP_FALSE;
|
||||||
|
|
||||||
|
|
|
@ -1436,28 +1436,7 @@ model_removePlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index )
|
||||||
} /* model_removePlayerTile */
|
} /* model_removePlayerTile */
|
||||||
|
|
||||||
void
|
void
|
||||||
model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const MoveInfo* mi )
|
model_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles )
|
||||||
{
|
|
||||||
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 )
|
|
||||||
{
|
{
|
||||||
XP_ASSERT( turn >= 0 );
|
XP_ASSERT( turn >= 0 );
|
||||||
PlayerCtxt* player = &model->players[turn];
|
PlayerCtxt* player = &model->players[turn];
|
||||||
|
|
|
@ -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_getPlayerTile( const ModelCtxt* model, XP_S16 turn, XP_S16 index );
|
||||||
|
|
||||||
Tile model_removePlayerTile( 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_removePlayerTiles( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles );
|
||||||
void model_removePlayerTiles2( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles );
|
|
||||||
void model_addPlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index,
|
void model_addPlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index,
|
||||||
Tile tile );
|
Tile tile );
|
||||||
void model_moveTileOnTray( ModelCtxt* model, XP_S16 turn, XP_S16 indexCur,
|
void model_moveTileOnTray( ModelCtxt* model, XP_S16 turn, XP_S16 indexCur,
|
||||||
|
|
|
@ -48,10 +48,10 @@ enum {
|
||||||
};
|
};
|
||||||
typedef XP_U8 GameEndReason;
|
typedef XP_U8 GameEndReason;
|
||||||
|
|
||||||
typedef enum {DUPE_STUFF_TRADES_SERVER,
|
typedef enum { DUPE_STUFF_TRADES_SERVER,
|
||||||
DUPE_STUFF_MOVES_SERVER,
|
DUPE_STUFF_MOVES_SERVER,
|
||||||
DUPE_STUFF_MOVE_CLIENT,
|
DUPE_STUFF_MOVE_CLIENT,
|
||||||
DUPE_STUFF_PAUSE,
|
DUPE_STUFF_PAUSE,
|
||||||
} DUPE_STUFF;
|
} DUPE_STUFF;
|
||||||
|
|
||||||
typedef struct ServerPlayer {
|
typedef struct ServerPlayer {
|
||||||
|
@ -140,7 +140,7 @@ struct ServerCtxt {
|
||||||
# define ROBOTWAITING(s) XP_FALSE
|
# define ROBOTWAITING(s) XP_FALSE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
# define dupTimerRunning() server_canPause(server)
|
# define dupe_timerRunning() server_canPause(server)
|
||||||
|
|
||||||
|
|
||||||
#define NPASSES_OK(s) model_recentPassCountOk((s)->vol.model)
|
#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
|
static void
|
||||||
autoPause( ServerCtxt* server )
|
dupe_autoPause( ServerCtxt* server )
|
||||||
{
|
{
|
||||||
XP_LOGF( "%s()", __func__ );
|
XP_LOGF( "%s()", __func__ );
|
||||||
|
|
||||||
|
@ -1214,7 +1214,7 @@ dupe_handleServerTrade( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
|
|
||||||
ModelCtxt* model = server->vol.model;
|
ModelCtxt* model = server->vol.model;
|
||||||
model_resetCurrentTurn( model, DUP_PLAYER );
|
model_resetCurrentTurn( model, DUP_PLAYER );
|
||||||
model_removePlayerTiles2( model, DUP_PLAYER, &oldTiles );
|
model_removePlayerTiles( model, DUP_PLAYER, &oldTiles );
|
||||||
pool_replaceTiles( server->pool, &oldTiles );
|
pool_replaceTiles( server->pool, &oldTiles );
|
||||||
pool_removeTiles( server->pool, &newTiles );
|
pool_removeTiles( server->pool, &newTiles );
|
||||||
|
|
||||||
|
@ -2969,7 +2969,7 @@ reflectMove( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
#endif /* XWFEATURE_STANDALONE_ONLY */
|
#endif /* XWFEATURE_STANDALONE_ONLY */
|
||||||
|
|
||||||
static void
|
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 )
|
XP_U16* winner, XP_U16* winningNTiles )
|
||||||
{
|
{
|
||||||
ModelCtxt* model = server->vol.model;
|
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;
|
*winner = moveData[winnerIndx].player;
|
||||||
*winningNTiles = moveData[winnerIndx].nTiles;
|
*winningNTiles = moveData[winnerIndx].nTiles;
|
||||||
/* This fires: I need the reassign-no-moves thing */
|
/* 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
|
static XP_Bool
|
||||||
allForced( const ServerCtxt* server )
|
dupe_allForced( const ServerCtxt* server )
|
||||||
{
|
{
|
||||||
XP_Bool result = XP_TRUE;
|
XP_Bool result = XP_TRUE;
|
||||||
for ( XP_U16 ii = 0; result && ii < server->vol.gi->nPlayers; ++ii ) {
|
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 winner;
|
||||||
XP_U16 nTiles;
|
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
|
/* 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
|
a 0. Unless we're running a timer, in which case it's most likely
|
||||||
noboby's playing, so pause the game instead. */
|
noboby's playing, so pause the game instead. */
|
||||||
if ( 0 == scores[winner] && 0 < pool_getNTilesLeft(server->pool) ) {
|
if ( 0 == scores[winner] && 0 < pool_getNTilesLeft(server->pool) ) {
|
||||||
if ( dupTimerRunning() && allForced( server ) ) {
|
if ( dupe_timerRunning() && dupe_allForced( server ) ) {
|
||||||
autoPause( server );
|
dupe_autoPause( server );
|
||||||
} else {
|
} else {
|
||||||
dupe_makeAndReportTrade( server );
|
dupe_makeAndReportTrade( server );
|
||||||
}
|
}
|
||||||
|
@ -3095,7 +3095,7 @@ dupe_makeAndReportTrade( ServerCtxt* server )
|
||||||
model_resetCurrentTurn( model, DUP_PLAYER );
|
model_resetCurrentTurn( model, DUP_PLAYER );
|
||||||
|
|
||||||
TrayTileSet oldTiles = *model_getPlayerTiles( 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 );
|
pool_replaceTiles( pool, &oldTiles );
|
||||||
|
|
||||||
TrayTileSet newTiles = {0};
|
TrayTileSet newTiles = {0};
|
||||||
|
@ -3215,7 +3215,7 @@ dupe_receivePause( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
}
|
}
|
||||||
|
|
||||||
static XP_Bool
|
static XP_Bool
|
||||||
handleDupeStuff( ServerCtxt* server, XWStreamCtxt* stream )
|
dupe_handleStuff( ServerCtxt* server, XWStreamCtxt* stream )
|
||||||
{
|
{
|
||||||
XP_Bool accepted;
|
XP_Bool accepted;
|
||||||
XP_Bool isServer = amServer( server );
|
XP_Bool isServer = amServer( server );
|
||||||
|
@ -3293,7 +3293,7 @@ dupe_commitAndReportMove( ServerCtxt* server, XP_U16 winner,
|
||||||
static void
|
static void
|
||||||
dupe_forceCommits( ServerCtxt* server )
|
dupe_forceCommits( ServerCtxt* server )
|
||||||
{
|
{
|
||||||
if ( dupTimerRunning() ) {
|
if ( dupe_timerRunning() ) {
|
||||||
XP_U32 now = dutil_getCurSeconds( server->vol.dutil );
|
XP_U32 now = dutil_getCurSeconds( server->vol.dutil );
|
||||||
if ( server->nv.dupTimerExpires <= now ) {
|
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
|
guest, I care only about local players. If I'm a host or standalone, I care
|
||||||
about everything. */
|
about everything. */
|
||||||
static void
|
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* allDoneP, XP_Bool* allLocalsDoneP )
|
||||||
{
|
{
|
||||||
XP_Bool allDone = XP_TRUE;
|
XP_Bool allDone = XP_TRUE;
|
||||||
|
@ -3355,7 +3355,7 @@ dupe_checkTurns( ServerCtxt* server )
|
||||||
XP_Bool allLocalsDone = XP_TRUE;
|
XP_Bool allLocalsDone = XP_TRUE;
|
||||||
XP_Bool amServer = server->vol.gi->serverRole == SERVER_ISSERVER
|
XP_Bool amServer = server->vol.gi->serverRole == SERVER_ISSERVER
|
||||||
|| server->vol.gi->serverRole == SERVER_STANDALONE;
|
|| server->vol.gi->serverRole == SERVER_STANDALONE;
|
||||||
checkWhatsDone( server, amServer, &allDone, &allLocalsDone );
|
dupe_checkWhatsDone( server, amServer, &allDone, &allLocalsDone );
|
||||||
|
|
||||||
XP_LOGF( "%s(): allDone: %d", __func__, allDone );
|
XP_LOGF( "%s(): allDone: %d", __func__, allDone );
|
||||||
|
|
||||||
|
@ -3604,9 +3604,6 @@ finishMove( ServerCtxt* server, TrayTileSet* newTiles, XP_U16 turn )
|
||||||
model_getNumTilesInTray( model, turn ) );
|
model_getNumTilesInTray( model, turn ) );
|
||||||
} /* finishMove */
|
} /* finishMove */
|
||||||
|
|
||||||
/* return XP_TRUE; */
|
|
||||||
/* } /\* server_commitMove *\/ */
|
|
||||||
|
|
||||||
XP_Bool
|
XP_Bool
|
||||||
server_commitTrade( ServerCtxt* server, const TrayTileSet* oldTiles,
|
server_commitTrade( ServerCtxt* server, const TrayTileSet* oldTiles,
|
||||||
TrayTileSet* newTilesP )
|
TrayTileSet* newTilesP )
|
||||||
|
@ -4146,7 +4143,7 @@ server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incoming )
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XWPROTO_DUPE_STUFF:
|
case XWPROTO_DUPE_STUFF:
|
||||||
accepted = handleDupeStuff( server, incoming );
|
accepted = dupe_handleStuff( server, incoming );
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
XP_WARNF( "%s: Unknown code on incoming message: %d\n",
|
XP_WARNF( "%s: Unknown code on incoming message: %d\n",
|
||||||
|
|
|
@ -105,6 +105,6 @@ void smsproto_freeMsgArray( SMSProto* state, SMSMsgArray* arr );
|
||||||
# ifdef DEBUG
|
# ifdef DEBUG
|
||||||
void smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil );
|
void smsproto_runTests( MPFORMAL XW_DUtilCtxt* dutil );
|
||||||
# else
|
# else
|
||||||
# define smsproto_runTests( p1, p2 )
|
# define smsproto_runTests( p1, p2 )
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -694,7 +694,7 @@ def mkParser():
|
||||||
parser.add_argument('--use-gtk', dest = 'USE_GTK', default = False, action = 'store_true',
|
parser.add_argument('--use-gtk', dest = 'USE_GTK', default = False, action = 'store_true',
|
||||||
help = 'run games using gtk instead of ncurses')
|
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')
|
help = 'this fraction played in duplicate mode')
|
||||||
|
|
||||||
# #
|
# #
|
||||||
|
|
Loading…
Reference in a new issue