diff --git a/xwords4/common/server.c b/xwords4/common/server.c index e665867c9..6ac29c723 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -1612,6 +1612,61 @@ assignTilesToAll( ServerCtxt* server ) } /* assignTilesToAll */ +#ifdef TEXT_MODEL +void +server_assignTiles( ServerCtxt* server, XP_U16 turn, + Tile* tiles, XP_U16 nTiles ) +{ + TrayTileSet newTiles; + XP_U16 ii; + + newTiles.nTiles = nTiles; + + if ( server->pool == NULL ) { + server->pool = pool_make( MPPARM_NOCOMMA(server->mpool) ); + pool_initFromDict( server->pool, + model_getDictionary(server->vol.model) ); + } + + for ( ii = 0; ii < nTiles; ++ii ) { + newTiles.tiles[ii] = tiles[ii]; + } + pool_removeTiles( server->pool, &newTiles ); + model_assignPlayerTiles( server->vol.model, turn, &newTiles ); +} + +void +server_genMoveList( ServerCtxt* server, MovePrintFunc proc, + void* closure ) +{ + XP_U16 turn = 0; + XP_Bool ignore; + const TrayTileSet* tileSet; + ModelCtxt* model = server->vol.model; + MoveInfo ignoreMI; + + tileSet = model_getPlayerTiles( model, turn ); + + EngineCtxt* engine = server_getEngineFor( server, turn ); + engine_reset( engine ); + engine_setPrinter( engine, proc, closure ); + + (void)engine_findMove( server_getEngineFor( server, turn ), + model, turn, tileSet->tiles, tileSet->nTiles, + XP_FALSE, 1, &ignore, &ignoreMI ); +} + +void +server_genMoveListWith( ServerCtxt* server, + Tile* tiles, XP_U16 nTiles, + MovePrintFunc proc, void* closure ) +{ + server_assignTiles( server, 0, tiles, nTiles ); + server_genMoveList( server, proc, closure ); +} + +#endif + #ifndef XWFEATURE_STANDALONE_ONLY static void getPlayerTime( ServerCtxt* server, XWStreamCtxt* stream, XP_U16 turn ) diff --git a/xwords4/common/server.h b/xwords4/common/server.h index d7b532554..1184c2b7a 100644 --- a/xwords4/common/server.h +++ b/xwords4/common/server.h @@ -98,6 +98,16 @@ XP_S16 server_countTilesInPool( ServerCtxt* server ); XP_Bool server_do( ServerCtxt* server ); +#ifdef TEXT_MODEL +void server_assignTiles( ServerCtxt* server, XP_U16 turn, + Tile* tiles, XP_U16 nTiles ); +void server_genMoveList( ServerCtxt* server, MovePrintFunc proc, + void* closure ); +void server_genMoveListWith( ServerCtxt* server, + Tile* tiles, XP_U16 nTiles, + MovePrintFunc proc, void* closure ); +#endif + XP_Bool server_commitMove( ServerCtxt* server ); XP_Bool server_commitTrade( ServerCtxt* server, TileBit bits );