mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
sort assigned tiles before putting them in the move stack. Fixes hash
comparison failure when devices are using sort-tiles option.
This commit is contained in:
parent
44a6653166
commit
eb2f5ff6eb
1 changed files with 27 additions and 20 deletions
|
@ -72,6 +72,7 @@ static void buildModelFromStack( ModelCtxt* model, StackCtxt* stack,
|
||||||
MovePrintFuncPost mpfpo, void* closure );
|
MovePrintFuncPost mpfpo, void* closure );
|
||||||
static void setPendingCounts( ModelCtxt* model, XP_S16 turn );
|
static void setPendingCounts( ModelCtxt* model, XP_S16 turn );
|
||||||
static XP_S16 setContains( const TrayTileSet* tiles, Tile tile );
|
static XP_S16 setContains( const TrayTileSet* tiles, Tile tile );
|
||||||
|
static void sortTiles( TrayTileSet* dest, const TrayTileSet* src );
|
||||||
static void removeTile( TrayTileSet* tiles, XP_U16 index );
|
static void removeTile( TrayTileSet* tiles, XP_U16 index );
|
||||||
static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
static void loadPlayerCtxt( const ModelCtxt* model, XWStreamCtxt* stream,
|
||||||
XP_U16 version, PlayerCtxt* pc );
|
XP_U16 version, PlayerCtxt* pc );
|
||||||
|
@ -1765,7 +1766,9 @@ model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||||
const TrayTileSet* tiles )
|
const TrayTileSet* tiles )
|
||||||
{
|
{
|
||||||
XP_ASSERT( turn >= 0 );
|
XP_ASSERT( turn >= 0 );
|
||||||
stack_addAssign( model->vol.stack, turn, tiles );
|
TrayTileSet sorted;
|
||||||
|
sortTiles( &sorted, tiles );
|
||||||
|
stack_addAssign( model->vol.stack, turn, &sorted );
|
||||||
|
|
||||||
assignPlayerTiles( model, turn, tiles );
|
assignPlayerTiles( model, turn, tiles );
|
||||||
} /* model_assignPlayerTiles */
|
} /* model_assignPlayerTiles */
|
||||||
|
@ -1773,30 +1776,17 @@ model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||||
void
|
void
|
||||||
model_sortTiles( ModelCtxt* model, XP_S16 turn )
|
model_sortTiles( ModelCtxt* model, XP_S16 turn )
|
||||||
{
|
{
|
||||||
PlayerCtxt* player;
|
|
||||||
XP_S16 ii;
|
|
||||||
TrayTileSet tiles = { .nTiles = 0 };
|
|
||||||
XP_S16 nTiles;
|
XP_S16 nTiles;
|
||||||
|
|
||||||
XP_ASSERT( turn >= 0 );
|
TrayTileSet sorted;
|
||||||
player = &model->players[turn];
|
sortTiles( &sorted, model_getPlayerTiles( model, turn ) );
|
||||||
|
|
||||||
for ( nTiles = model_getNumTilesInTray( model, turn ) - 1;
|
nTiles = sorted.nTiles;
|
||||||
nTiles >= 0; --nTiles ) {
|
while ( nTiles > 0 ) {
|
||||||
Tile min = 0xFF;
|
removePlayerTile( model, turn, --nTiles );
|
||||||
XP_U16 minIndex = 0;
|
|
||||||
for ( ii = 0; ii <= nTiles; ++ii ) {
|
|
||||||
Tile tile = player->trayTiles.tiles[ii];
|
|
||||||
if ( tile < min ) {
|
|
||||||
min = tile;
|
|
||||||
minIndex = ii;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tiles.tiles[tiles.nTiles++] =
|
|
||||||
removePlayerTile( model, turn, minIndex );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
assignPlayerTiles( model, turn, &tiles );
|
assignPlayerTiles( model, turn, &sorted );
|
||||||
} /* model_sortTiles */
|
} /* model_sortTiles */
|
||||||
|
|
||||||
XP_U16
|
XP_U16
|
||||||
|
@ -2449,6 +2439,23 @@ setContains( const TrayTileSet* tiles, Tile tile )
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
sortTiles( TrayTileSet* dest, const TrayTileSet* src )
|
||||||
|
{
|
||||||
|
TrayTileSet tmp = *src;
|
||||||
|
dest->nTiles = 0;
|
||||||
|
while ( 0 < tmp.nTiles ) {
|
||||||
|
XP_U16 ii, smallest;
|
||||||
|
for ( smallest = ii = 0; ii < tmp.nTiles; ++ii ) {
|
||||||
|
if ( tmp.tiles[ii] < tmp.tiles[smallest] ) {
|
||||||
|
smallest = ii;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dest->tiles[dest->nTiles++] = tmp.tiles[smallest];
|
||||||
|
removeTile( &tmp, smallest );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CPLUS
|
#ifdef CPLUS
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue