fix crash with 23x23 (linux only); allow 6 blanks

Portuguese will want six blanks for a 21x21 board, so might as well
not crash in case that becomes a thing.
This commit is contained in:
Eric House 2022-04-04 17:28:10 +02:00
parent bd6f6e373c
commit 1c9fe6745c
3 changed files with 28 additions and 17 deletions

View file

@ -548,17 +548,23 @@ getCountsFor( const DictionaryCtxt* dict, XP_U16 nCols )
/* don't have it in the wordlist? Extrapolate */
if ( !found ) {
const Tile blank = dict_getBlankTile( dict );
XP_U16 pct = (nCols * nCols * 100) / (15 * 15);
XP_U8* src15 = dict->counts[15>>1];
XP_ASSERT( !!src15 );
for ( int ii = 0; ii < dict->nFaces; ++ii ) {
XP_U16 count = src15[ii];
for ( Tile tile = 0; tile < dict->nFaces; ++tile ) {
XP_U16 count = src15[tile];
XP_U16 newCount = count * pct / 100;
if ( 50 < (count * pct) % 100 ) {
++newCount;
}
counts[ii] = newCount;
XP_ASSERT( tile != blank || newCount <= MAX_NUM_BLANKS );
if ( tile == blank && newCount > MAX_NUM_BLANKS ) {
newCount = MAX_NUM_BLANKS;
}
counts[tile] = newCount;
}
}
}

View file

@ -419,19 +419,24 @@ getSquareBonus( XP_U16 nCols, XP_U16 col, XP_U16 row )
row = tmp;
}
/* For a smaller board, skip the outer "rings" */
XP_U16 adj = (21 - nCols) / 2;
col += adj;
row += adj;
XP_U16 index = col;
for ( XP_U16 ii = 1; ii <= row; ++ii ) {
index += ii;
}
/* For a smaller board, skip the outer "rings." For larger,
outer rings are empty */
XWBonusType result = BONUS_NONE;
if ( index < VSIZE(sTwentyOne)) {
result = sTwentyOne[index];
XP_U16 adj = (21 - nCols) / 2;
if ( 0 <= adj ) {
col += adj;
row += adj;
if ( col <= 21 && row <= 21 ) {
XP_U16 index = col;
for ( XP_U16 ii = 1; ii <= row; ++ii ) {
index += ii;
}
if ( index < VSIZE(sTwentyOne)) {
result = sTwentyOne[index];
}
}
}
return result;
}

View file

@ -51,8 +51,8 @@ extern "C" {
#define CELL_OWNER(t) (((t)&CELL_OWNER_MASK) >> CELL_OWNER_OFFSET)
#define MAX_UNIQUE_TILES 64 /* max tile non-blank faces */
#define MAX_NUM_BLANKS 4
/* Portuguese has 3 for a 15x15 game; can go higer on larger boards */
#define MAX_NUM_BLANKS 6
typedef struct BlankQueue {
XP_U16 nBlanks;