diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 76dbe316e..eadeb0ace 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -1838,7 +1838,7 @@ model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn, { XP_ASSERT( turn >= 0 ); TrayTileSet sorted; - sortTiles( &sorted, tiles ); + sortTiles( &sorted, tiles, 0 ); stack_addAssign( model->vol.stack, turn, &sorted ); assignPlayerTiles( model, turn, tiles ); @@ -1850,7 +1850,8 @@ model_sortTiles( ModelCtxt* model, XP_S16 turn ) XP_S16 nTiles; TrayTileSet sorted; - sortTiles( &sorted, model_getPlayerTiles( model, turn ) ); + const TrayTileSet* curTiles = model_getPlayerTiles( model, turn ); + sortTiles( &sorted, curTiles, XP_MIN( 3, curTiles->nTiles) ); nTiles = sorted.nTiles; while ( nTiles > 0 ) { diff --git a/xwords4/common/movestak.c b/xwords4/common/movestak.c index 7f3397023..401927347 100644 --- a/xwords4/common/movestak.c +++ b/xwords4/common/movestak.c @@ -97,7 +97,7 @@ augmentFor( XP_U32 hash, const StackEntry* entry ) switch( entry->moveType ) { case ASSIGN_TYPE: { TrayTileSet tiles; - sortTiles( &tiles, &entry->u.assign.tiles ); + sortTiles( &tiles, &entry->u.assign.tiles, 0 ); hash = augmentHash( hash, (XP_U8*)&tiles, sizeof(tiles) ); } break; diff --git a/xwords4/common/strutils.c b/xwords4/common/strutils.c index 4b1cd48b9..6ccd67673 100644 --- a/xwords4/common/strutils.c +++ b/xwords4/common/strutils.c @@ -84,13 +84,18 @@ removeTile( TrayTileSet* tiles, XP_U16 index ) } void -sortTiles( TrayTileSet* dest, const TrayTileSet* src ) +sortTiles( TrayTileSet* dest, const TrayTileSet* src, XP_U16 skip ) { + XP_ASSERT( src->nTiles >= skip ); TrayTileSet tmp = *src; - dest->nTiles = 0; - while ( 0 < tmp.nTiles ) { + + /* Copy in the ones we're not sorting */ + dest->nTiles = skip; + XP_MEMCPY( &dest->tiles, &tmp.tiles, skip * sizeof(tmp.tiles[0]) ); + + while ( skip < tmp.nTiles ) { XP_U16 ii, smallest; - for ( smallest = ii = 0; ii < tmp.nTiles; ++ii ) { + for ( smallest = ii = skip; ii < tmp.nTiles; ++ii ) { if ( tmp.tiles[ii] < tmp.tiles[smallest] ) { smallest = ii; } diff --git a/xwords4/common/strutils.h b/xwords4/common/strutils.h index b4a200fb7..00e2e6116 100644 --- a/xwords4/common/strutils.h +++ b/xwords4/common/strutils.h @@ -34,7 +34,7 @@ XP_U16 bitsForMax( XP_U32 n ); void traySetToStream( XWStreamCtxt* stream, const TrayTileSet* ts ); void traySetFromStream( XWStreamCtxt* stream, TrayTileSet* ts ); -void sortTiles( TrayTileSet* dest, const TrayTileSet* src ); +void sortTiles( TrayTileSet* dest, const TrayTileSet* src, XP_U16 skip ); void removeTile( TrayTileSet* tiles, XP_U16 index ); XP_S32 signedFromStream( XWStreamCtxt* stream, XP_U16 nBits );