From 1c9fe6745cf995c1dde1f4307ef268f3f50c5efd Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 4 Apr 2022 17:28:10 +0200 Subject: [PATCH] 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. --- xwords4/common/dictnry.c | 12 +++++++++--- xwords4/common/model.c | 29 +++++++++++++++++------------ xwords4/common/model.h | 4 ++-- 3 files changed, 28 insertions(+), 17 deletions(-) diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 28e75ef23..9ccc75ab0 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -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; } } } diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 7aae4cd98..88a6d322e 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -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; } diff --git a/xwords4/common/model.h b/xwords4/common/model.h index 581abb1c7..e2df23918 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -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;