mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
server_formatRemainingTiles and server_formatDictCounts
This commit is contained in:
parent
a80a8dd431
commit
a4938db8fe
2 changed files with 81 additions and 18 deletions
|
@ -2270,8 +2270,75 @@ server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incomming )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void
|
void
|
||||||
server_formatPoolCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
XP_U16 nCols )
|
XP_U16 nCols )
|
||||||
|
{
|
||||||
|
DictionaryCtxt* dict;
|
||||||
|
Tile tile;
|
||||||
|
XP_U16 nChars, nPrinted;
|
||||||
|
XP_UCHAR buf[48];
|
||||||
|
XP_UCHAR* fmt = util_getUserString( server->vol.util, STRS_VALUES_HEADER );
|
||||||
|
XP_UCHAR* dname;
|
||||||
|
|
||||||
|
XP_ASSERT( !!server->vol.model );
|
||||||
|
|
||||||
|
dict = model_getDictionary( server->vol.model );
|
||||||
|
dname = dict_getName( dict );
|
||||||
|
StrPrintF( buf, fmt, dname );
|
||||||
|
stream_putBytes( stream, buf, XP_STRLEN(buf) );
|
||||||
|
|
||||||
|
nChars = dict_numTileFaces( dict );
|
||||||
|
|
||||||
|
for ( tile = 0, nPrinted = 0; ; ) {
|
||||||
|
XP_UCHAR buf[24];
|
||||||
|
XP_UCHAR face[4];
|
||||||
|
XP_U16 count, value;
|
||||||
|
|
||||||
|
count = dict_numTiles( dict, tile );
|
||||||
|
|
||||||
|
if ( count > 0 ) {
|
||||||
|
dict_tilesToString( dict, &tile, 1, face );
|
||||||
|
value = dict_getTileValue( dict, tile );
|
||||||
|
|
||||||
|
XP_SNPRINTF( buf, sizeof(buf), (XP_UCHAR*)"%s: %d/%d",
|
||||||
|
face, count, value );
|
||||||
|
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ++tile >= nChars ) {
|
||||||
|
break;
|
||||||
|
} else if ( count > 0 ) {
|
||||||
|
if ( ++nPrinted % nCols == 0 ) {
|
||||||
|
stream_putBytes( stream, XP_CR, (XP_U16)XP_STRLEN(XP_CR) );
|
||||||
|
} else {
|
||||||
|
stream_putBytes( stream, (void*)" ", 3 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* server_formatDictCounts */
|
||||||
|
|
||||||
|
static void
|
||||||
|
putNTiles( XP_UCHAR* buf, const XP_UCHAR* face, XP_U16 count )
|
||||||
|
{
|
||||||
|
XP_U16 done = 0;
|
||||||
|
XP_U16 len = XP_STRLEN( face );
|
||||||
|
while ( count-- != 0 ) {
|
||||||
|
XP_STRCAT( buf + done, face );
|
||||||
|
done += len;
|
||||||
|
if ( count > 0 ) {
|
||||||
|
XP_STRCAT( buf + done, "." );
|
||||||
|
++done;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* putNTiles */
|
||||||
|
|
||||||
|
/* Print the faces of all tiles left in the pool, including those currently in
|
||||||
|
* trays !unless! player is >= 0, in which case his tiles get removed from the
|
||||||
|
* pool. The idea is to show him what tiles are left in play.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
|
XP_S16 player )
|
||||||
{
|
{
|
||||||
DictionaryCtxt* dict;
|
DictionaryCtxt* dict;
|
||||||
Tile tile;
|
Tile tile;
|
||||||
|
@ -2286,7 +2353,7 @@ server_formatPoolCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
XP_ASSERT( !!server->vol.model );
|
XP_ASSERT( !!server->vol.model );
|
||||||
|
|
||||||
XP_MEMSET( counts, 0, sizeof(counts) );
|
XP_MEMSET( counts, 0, sizeof(counts) );
|
||||||
model_countAllTrayTiles( server->vol.model, counts );
|
model_countAllTrayTiles( server->vol.model, counts, player );
|
||||||
|
|
||||||
dict = model_getDictionary( server->vol.model );
|
dict = model_getDictionary( server->vol.model );
|
||||||
nChars = dict_numTileFaces( dict );
|
nChars = dict_numTileFaces( dict );
|
||||||
|
@ -2294,33 +2361,26 @@ server_formatPoolCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
for ( tile = 0, nPrinted = 0; ; ) {
|
for ( tile = 0, nPrinted = 0; ; ) {
|
||||||
XP_UCHAR buf[24];
|
XP_UCHAR buf[24];
|
||||||
XP_UCHAR face[4];
|
XP_UCHAR face[4];
|
||||||
XP_U16 count, value;
|
XP_U16 count;
|
||||||
XP_S16 nRemaining; /* signed so assertion will work */
|
|
||||||
|
|
||||||
count = dict_numTiles( dict, tile );
|
count = pool_getNTilesLeftFor( pool, tile ) + counts[tile];
|
||||||
|
|
||||||
if ( count > 0 ) {
|
if ( count > 0 ) {
|
||||||
dict_tilesToString( dict, &tile, 1, face );
|
dict_tilesToString( dict, &tile, 1, face );
|
||||||
nRemaining = pool_getNTilesLeftFor( pool, tile ) + counts[tile];
|
|
||||||
XP_ASSERT( nRemaining >= 0 );
|
|
||||||
value = dict_getTileValue( dict, tile );
|
|
||||||
|
|
||||||
XP_SNPRINTF( buf, sizeof(buf), (XP_UCHAR*)"%s: %d[%d] %d",
|
buf[0] = '\0';
|
||||||
face, count, nRemaining, value );
|
putNTiles( buf, face, count );
|
||||||
|
|
||||||
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
stream_putBytes( stream, buf, (XP_U16)XP_STRLEN(buf) );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ++tile >= nChars ) {
|
if ( ++tile >= nChars ) {
|
||||||
break;
|
break;
|
||||||
} else if ( count > 0 ) {
|
} else if ( count > 0 ) {
|
||||||
if ( ++nPrinted % nCols == 0 ) {
|
stream_putBytes( stream, (void*)" ", 3 );
|
||||||
stream_putBytes( stream, XP_CR, (XP_U16)XP_STRLEN(XP_CR) );
|
|
||||||
} else {
|
|
||||||
stream_putBytes( stream, (void*)" ", 3 );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} /* server_formatPoolCounts */
|
} /* server_formatRemainingTiles */
|
||||||
|
|
||||||
#define IMPOSSIBLY_LOW_SCORE -1000
|
#define IMPOSSIBLY_LOW_SCORE -1000
|
||||||
void
|
void
|
||||||
|
|
|
@ -113,8 +113,11 @@ XP_Bool server_receiveMessage( ServerCtxt* server, XWStreamCtxt* incomming );
|
||||||
void server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream );
|
void server_initClientConnection( ServerCtxt* server, XWStreamCtxt* stream );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void server_formatPoolCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
void server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
XP_U16 nCols );
|
XP_U16 nCols );
|
||||||
|
void server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream,
|
||||||
|
XP_S16 player );
|
||||||
|
|
||||||
void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream );
|
void server_writeFinalScores( ServerCtxt* server, XWStreamCtxt* stream );
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
|
|
Loading…
Reference in a new issue