mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2024-12-28 09:58:30 +01:00
Add model_sortTiles(); use it; fix some comments and const decls.
Sorting always happens now when tiles added; needs to be based on a preference.
This commit is contained in:
parent
529f3df726
commit
e0dd3701a0
5 changed files with 46 additions and 10 deletions
|
@ -58,7 +58,7 @@ static CellTile getModelTileRaw( const ModelCtxt* model, XP_U16 col,
|
|||
static void setModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row,
|
||||
CellTile tile );
|
||||
static void assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||
TrayTileSet* tiles );
|
||||
const TrayTileSet* tiles );
|
||||
static void makeTileTrade( ModelCtxt* model, XP_S16 player,
|
||||
TrayTileSet* oldTiles, TrayTileSet* newTiles );
|
||||
static XP_S16 commitTurn( ModelCtxt* model, XP_S16 turn,
|
||||
|
@ -1349,22 +1349,52 @@ model_moveTileOnTray( ModelCtxt* model, XP_S16 turn, XP_S16 indexCur,
|
|||
} /* model_moveTileOnTray */
|
||||
|
||||
static void
|
||||
assignPlayerTiles( ModelCtxt* model, XP_S16 turn, TrayTileSet* tiles )
|
||||
assignPlayerTiles( ModelCtxt* model, XP_S16 turn, const TrayTileSet* tiles )
|
||||
{
|
||||
Tile* tilep = tiles->tiles;
|
||||
const Tile* tilep = tiles->tiles;
|
||||
XP_U16 nTiles = tiles->nTiles;
|
||||
while ( nTiles-- ) {
|
||||
model_addPlayerTile( model, turn, -1, *tilep++ );
|
||||
}
|
||||
} /* model_addPlayerTiles */
|
||||
} /* assignPlayerTiles */
|
||||
|
||||
void
|
||||
model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn, TrayTileSet* tiles )
|
||||
model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||
const TrayTileSet* tiles )
|
||||
{
|
||||
stack_addAssign( model->vol.stack, turn, tiles );
|
||||
|
||||
assignPlayerTiles( model, turn, tiles );
|
||||
} /* model_addPlayerTiles */
|
||||
} /* model_assignPlayerTiles */
|
||||
|
||||
void
|
||||
model_sortTiles( ModelCtxt* model, XP_S16 turn )
|
||||
{
|
||||
PlayerCtxt* player = &model->players[turn];
|
||||
XP_S16 ii;
|
||||
|
||||
TrayTileSet tiles = { .nTiles = 0 };
|
||||
XP_S16 nTiles;
|
||||
|
||||
XP_ASSERT( turn >= 0 );
|
||||
|
||||
for ( nTiles = model_getNumTilesInTray( model, turn ) - 1;
|
||||
nTiles >= 0; --nTiles ) {
|
||||
Tile min = 0xFF;
|
||||
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 );
|
||||
} /* model_sortTiles */
|
||||
|
||||
XP_U16
|
||||
model_getNumTilesInTray( ModelCtxt* model, XP_S16 turn )
|
||||
|
@ -1373,7 +1403,7 @@ model_getNumTilesInTray( ModelCtxt* model, XP_S16 turn )
|
|||
XP_ASSERT( turn >= 0 );
|
||||
player = &model->players[turn];
|
||||
return player->trayTiles.nTiles;
|
||||
} /* model_getNumPlayerTiles */
|
||||
} /* model_getNumTilesInTray */
|
||||
|
||||
XP_U16
|
||||
model_getNumTilesTotal( ModelCtxt* model, XP_S16 turn )
|
||||
|
|
|
@ -126,7 +126,7 @@ void model_listPlacedBlanks( ModelCtxt* model, XP_U16 turn,
|
|||
XP_U16 model_getCellOwner( ModelCtxt* model, XP_U16 col, XP_U16 row );
|
||||
|
||||
void model_assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
|
||||
TrayTileSet* tiles );
|
||||
const TrayTileSet* tiles );
|
||||
Tile model_getPlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index );
|
||||
|
||||
Tile model_removePlayerTile( ModelCtxt* model, XP_S16 turn, XP_S16 index );
|
||||
|
@ -139,6 +139,7 @@ void model_moveTileOnTray( ModelCtxt* model, XP_S16 turn, XP_S16 indexCur,
|
|||
player. Don't even think about modifying the array!!!! */
|
||||
const TrayTileSet* model_getPlayerTiles( ModelCtxt* model, XP_S16 turn );
|
||||
|
||||
void model_sortTiles( ModelCtxt* model, XP_S16 turn );
|
||||
XP_U16 model_getNumTilesInTray( ModelCtxt* model, XP_S16 turn );
|
||||
XP_U16 model_getNumTilesTotal( ModelCtxt* model, XP_S16 turn );
|
||||
void model_moveBoardToTray( ModelCtxt* model, XP_S16 turn,
|
||||
|
|
|
@ -293,7 +293,7 @@ stack_addTrade( StackCtxt* stack, XP_U16 turn,
|
|||
} /* stack_addTrade */
|
||||
|
||||
void
|
||||
stack_addAssign( StackCtxt* stack, XP_U16 turn, TrayTileSet* tiles )
|
||||
stack_addAssign( StackCtxt* stack, XP_U16 turn, const TrayTileSet* tiles )
|
||||
{
|
||||
StackEntry move;
|
||||
|
||||
|
|
|
@ -79,7 +79,8 @@ void stack_addMove( StackCtxt* stack, XP_U16 turn, MoveInfo* moveInfo,
|
|||
void stack_addPhony( StackCtxt* stack, XP_U16 turn, MoveInfo* moveInfo );
|
||||
void stack_addTrade( StackCtxt* stack, XP_U16 turn,
|
||||
TrayTileSet* oldTiles, TrayTileSet* newTiles );
|
||||
void stack_addAssign( StackCtxt* stack, XP_U16 turn, TrayTileSet* tiles );
|
||||
void stack_addAssign( StackCtxt* stack, XP_U16 turn,
|
||||
const TrayTileSet* tiles );
|
||||
|
||||
XP_U16 stack_getNEntries( StackCtxt* stack );
|
||||
|
||||
|
|
|
@ -1116,6 +1116,8 @@ client_readInitialMessage( ServerCtxt* server, XWStreamCtxt* stream )
|
|||
/* remove what the server's assigned so we won't conflict
|
||||
later. */
|
||||
pool_removeTiles( pool, &tiles );
|
||||
|
||||
model_sortTiles( model, i );
|
||||
}
|
||||
|
||||
SETSTATE( server, XWSTATE_INTURN );
|
||||
|
@ -1580,6 +1582,7 @@ assignTilesToAll( ServerCtxt* server )
|
|||
TrayTileSet newTiles;
|
||||
fetchTiles( server, i, numAssigned, NULL, &newTiles );
|
||||
model_assignPlayerTiles( model, i, &newTiles );
|
||||
model_sortTiles( model, i );
|
||||
}
|
||||
|
||||
} /* assignTilesToAll */
|
||||
|
@ -2028,6 +2031,7 @@ server_commitMove( ServerCtxt* server )
|
|||
#endif
|
||||
|
||||
model_commitTurn( model, turn, &newTiles );
|
||||
model_sortTiles( model, turn );
|
||||
|
||||
if ( !isLegalMove && !isClient ) {
|
||||
badWordMoveUndoAndTellUser( server, &server->illegalWordInfo );
|
||||
|
|
Loading…
Reference in a new issue