mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
make number of tiles proportional to board size
Until there's a way to specify specifically for each size, adjusting from the built-in 15x15 tileset works reasonably well.
This commit is contained in:
parent
b34190d62d
commit
372d722b58
7 changed files with 42 additions and 21 deletions
|
@ -1086,7 +1086,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_dict_1getTilesInfo
|
|||
DictionaryCtxt* dict = (DictionaryCtxt*)dictPtr;
|
||||
XWStreamCtxt* stream = mem_stream_make( MPPARM(mpool) globalState->vtMgr,
|
||||
NULL, 0, NULL );
|
||||
dict_writeTilesInfo( dict, stream );
|
||||
dict_writeTilesInfo( dict, 15, stream );
|
||||
result = streamToJString( env, stream );
|
||||
stream_destroy( stream, env );
|
||||
|
||||
|
|
|
@ -477,10 +477,25 @@ dict_getNextTileString( const DictionaryCtxt* dict, Tile tile,
|
|||
}
|
||||
|
||||
XP_U16
|
||||
dict_numTiles( const DictionaryCtxt* dict, Tile tile )
|
||||
dict_numTilesForSize( const DictionaryCtxt* dict, Tile tile, XP_U16 nCols )
|
||||
{
|
||||
tile *= 2;
|
||||
return dict->countsAndValues[tile];
|
||||
XP_U16 count = dict->countsAndValues[tile];
|
||||
|
||||
/* Wordlists are built assuming 15x15 boards. Different sized boards need
|
||||
different numbers of tiles. The wordlist might provide for the size we
|
||||
have. If not, let's adjust the count based on how many squares we have
|
||||
vs. 15x15.
|
||||
*/
|
||||
XP_U16 pct = (nCols * nCols * 100) / (15 * 15);
|
||||
XP_U16 newCount = count * pct / 100;
|
||||
if ( 50 < (count * pct) % 100 ) {
|
||||
++newCount;
|
||||
}
|
||||
XP_LOGFF( "adjusted count %d to %d based on pct of %d", count, newCount, pct );
|
||||
count = newCount;
|
||||
|
||||
return count;
|
||||
} /* dict_numTiles */
|
||||
|
||||
XP_U16
|
||||
|
@ -631,7 +646,7 @@ dict_tilesAreSame( const DictionaryCtxt* dict1, const DictionaryCtxt* dict2 )
|
|||
} else if ( 0 != XP_STRCMP( face1, face2 ) ) {
|
||||
break;
|
||||
}
|
||||
if ( dict_numTiles( dict1, ii ) != dict_numTiles( dict2, ii ) ) {
|
||||
if ( dict_numTilesForSize( dict1, ii, 15 ) != dict_numTilesForSize( dict2, ii, 15 ) ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -662,12 +677,12 @@ ucharsToNarrow( const DictionaryCtxt* dict, XP_UCHAR* buf, XP_U16* bufsizep )
|
|||
|
||||
/* Summarize tile info in a way it can be presented to users */
|
||||
void
|
||||
dict_writeTilesInfo( const DictionaryCtxt* dict, XWStreamCtxt* stream )
|
||||
dict_writeTilesInfo( const DictionaryCtxt* dict, XP_U16 boardSize, XWStreamCtxt* stream )
|
||||
{
|
||||
XP_U16 nFaces = dict_numTileFaces( dict );
|
||||
for ( Tile tile = 0; tile < nFaces; ++tile ) {
|
||||
XP_U16 val = dict_getTileValue( dict, tile );
|
||||
XP_U16 count = dict_numTiles( dict, tile );
|
||||
XP_U16 count = dict_numTilesForSize( dict, tile, boardSize );
|
||||
const XP_UCHAR* face = dict_getTileString( dict, tile );
|
||||
XP_UCHAR buf[32];
|
||||
XP_SNPRINTF( buf, VSIZE(buf), "%s\t%d\t%d\n", face, count, val );
|
||||
|
|
|
@ -177,7 +177,7 @@ XP_Bool dict_tilesAreSame( const DictionaryCtxt* dict1,
|
|||
XP_Bool dict_hasBlankTile( const DictionaryCtxt* dict );
|
||||
Tile dict_getBlankTile( const DictionaryCtxt* dict );
|
||||
XP_U16 dict_getTileValue( const DictionaryCtxt* ctxt, Tile tile );
|
||||
XP_U16 dict_numTiles( const DictionaryCtxt* ctxt, Tile tile );
|
||||
XP_U16 dict_numTilesForSize( const DictionaryCtxt* ctxt, Tile tile, XP_U16 nCols );
|
||||
XP_U16 dict_numTileFaces( const DictionaryCtxt* ctxt );
|
||||
XP_U16 dict_getMaxTileChars( const DictionaryCtxt* ctxt );
|
||||
|
||||
|
@ -207,7 +207,8 @@ const XP_UCHAR* dict_getDesc( const DictionaryCtxt* dict );
|
|||
const XP_UCHAR* dict_getMd5Sum( const DictionaryCtxt* dict );
|
||||
XP_Bool dict_hasDuplicates( const DictionaryCtxt* dict );
|
||||
|
||||
void dict_writeTilesInfo( const DictionaryCtxt* ctxt, XWStreamCtxt* stream );
|
||||
void dict_writeTilesInfo( const DictionaryCtxt* ctxt, XP_U16 boardSize,
|
||||
XWStreamCtxt* stream );
|
||||
|
||||
void dict_writeToStream( const DictionaryCtxt* ctxt, XWStreamCtxt* stream );
|
||||
void dict_loadFromStream( DictionaryCtxt* dict, XWEnv xwe, XWStreamCtxt* stream );
|
||||
|
|
|
@ -242,7 +242,7 @@ pool_getNTilesLeftFor( const PoolContext* pool, Tile tile )
|
|||
} /* pool_remainingTileCount */
|
||||
|
||||
void
|
||||
pool_initFromDict( PoolContext* pool, const DictionaryCtxt* dict )
|
||||
pool_initFromDict( PoolContext* pool, const DictionaryCtxt* dict, XP_U16 nCols )
|
||||
{
|
||||
const XP_U16 numFaces = dict_numTileFaces( dict );
|
||||
|
||||
|
@ -253,9 +253,9 @@ pool_initFromDict( PoolContext* pool, const DictionaryCtxt* dict )
|
|||
numFaces * sizeof(pool->lettersLeft[0]) );
|
||||
pool->numTilesLeft = 0;
|
||||
|
||||
for ( Tile ii = 0; ii < numFaces; ++ii ) {
|
||||
XP_U16 numTiles = dict_numTiles( dict, ii );
|
||||
pool->lettersLeft[ii] = (XP_U8)numTiles;
|
||||
for ( Tile tile = 0; tile < numFaces; ++tile ) {
|
||||
XP_U16 numTiles = dict_numTilesForSize( dict, tile, nCols );
|
||||
pool->lettersLeft[tile] = (XP_U8)numTiles;
|
||||
pool->numTilesLeft += numTiles;
|
||||
}
|
||||
|
||||
|
|
|
@ -39,7 +39,8 @@ XP_U16 pool_getNTilesLeftFor( const PoolContext* pool, Tile tile );
|
|||
PoolContext* pool_make( MPFORMAL_NOCOMMA );
|
||||
|
||||
void pool_destroy( PoolContext* pool );
|
||||
void pool_initFromDict( PoolContext* pool, const DictionaryCtxt* dict );
|
||||
void pool_initFromDict( PoolContext* pool, const DictionaryCtxt* dict,
|
||||
XP_U16 nCols );
|
||||
|
||||
void pool_writeToStream( PoolContext* pool, XWStreamCtxt* stream );
|
||||
PoolContext* pool_makeFromStream( MPFORMAL XWStreamCtxt* stream );
|
||||
|
|
|
@ -2573,7 +2573,8 @@ makePoolOnce( ServerCtxt* server )
|
|||
if ( server->pool == NULL ) {
|
||||
server->pool = pool_make( MPPARM_NOCOMMA(server->mpool) );
|
||||
XP_STATUSF( "%s(): initing pool", __func__ );
|
||||
pool_initFromDict( server->pool, model_getDictionary(model));
|
||||
pool_initFromDict( server->pool, model_getDictionary(model),
|
||||
server->vol.gi->boardSize );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4330,12 +4331,12 @@ server_formatDictCounts( ServerCtxt* server, XWEnv xwe, XWStreamCtxt* stream,
|
|||
stream_catString( stream, buf );
|
||||
|
||||
nChars = dict_numTileFaces( dict );
|
||||
|
||||
XP_U16 boardSize = server->vol.gi->boardSize;
|
||||
for ( tile = 0, nPrinted = 0; ; ) {
|
||||
XP_UCHAR buf[128];
|
||||
XP_U16 count, value;
|
||||
|
||||
count = dict_numTiles( dict, tile );
|
||||
count = dict_numTilesForSize( dict, tile, boardSize );
|
||||
|
||||
if ( count > 0 ) {
|
||||
const XP_UCHAR* face = NULL;
|
||||
|
|
|
@ -30,7 +30,8 @@
|
|||
#include "gtkutils.h"
|
||||
#include "gtkask.h"
|
||||
|
||||
#define MAX_SIZE_CHOICES 32
|
||||
#define MIN_BOARD_SIZE 11
|
||||
#define MAX_BOARD_SIZE 23
|
||||
|
||||
#define BINGO_THRESHOLD "Bingo threshold"
|
||||
#define TRAY_SIZE "Tray size"
|
||||
|
@ -168,7 +169,7 @@ size_combo_changed( GtkComboBox* combo, gpointer gp )
|
|||
GtkNewGameState* state = (GtkNewGameState*)gp;
|
||||
gint index = gtk_combo_box_get_active( GTK_COMBO_BOX(combo) );
|
||||
if ( index >= 0 ) {
|
||||
state->nCols = MAX_COLS - index;
|
||||
state->nCols = MIN_BOARD_SIZE + (index * 2);
|
||||
XP_LOGF( "set nCols = %d", state->nCols );
|
||||
}
|
||||
} /* size_combo_changed */
|
||||
|
@ -348,14 +349,16 @@ addSizesRow( GtkNewGameState* state, GtkWidget* parent )
|
|||
gtk_widget_set_sensitive( boardSizeCombo, FALSE );
|
||||
}
|
||||
|
||||
for ( int ii = 0; ii < MAX_SIZE_CHOICES; ++ii ) {
|
||||
int curEntry = 0;
|
||||
for ( int siz = MIN_BOARD_SIZE; siz <= MAX_BOARD_SIZE; siz += 2 ) {
|
||||
char buf[10];
|
||||
XP_U16 siz = MAX_COLS - ii;
|
||||
// XP_U16 siz = MAX_COLS - ii;
|
||||
snprintf( buf, sizeof(buf), "%dx%d", siz, siz );
|
||||
gtk_combo_box_text_append_text( GTK_COMBO_BOX_TEXT(boardSizeCombo), buf );
|
||||
if ( siz == state->nCols ) {
|
||||
gtk_combo_box_set_active( GTK_COMBO_BOX(boardSizeCombo), ii );
|
||||
gtk_combo_box_set_active( GTK_COMBO_BOX(boardSizeCombo), curEntry );
|
||||
}
|
||||
++curEntry;
|
||||
}
|
||||
|
||||
g_signal_connect( boardSizeCombo, "changed",
|
||||
|
|
Loading…
Add table
Reference in a new issue