fix bug with printing last move score. Undo on the tmp model wasn't

working and so tiles added later got included.
This commit is contained in:
ehouse 2004-10-30 18:22:39 +00:00
parent 00cc411f39
commit 03eeac1d30

View file

@ -24,6 +24,7 @@
#include "xwstream.h" #include "xwstream.h"
#include "util.h" #include "util.h"
#include "pool.h" #include "pool.h"
#include "memstream.h"
#include "strutils.h" #include "strutils.h"
#include "LocalizedStrIncludes.h" #include "LocalizedStrIncludes.h"
@ -496,7 +497,9 @@ replaceNewTiles( ModelCtxt* model, PoolContext* pool, XP_U16 turn,
XP_ASSERT( index >= 0 ); XP_ASSERT( index >= 0 );
model_removePlayerTile( model, turn, index ); model_removePlayerTile( model, turn, index );
} }
if ( !!pool ) {
pool_replaceTiles( pool, tileSet); pool_replaceTiles( pool, tileSet);
}
} /* replaceNewTiles */ } /* replaceNewTiles */
/* Turn the most recent move into a phony. /* Turn the most recent move into a phony.
@ -563,9 +566,7 @@ model_undoLatestMoves( ModelCtxt* model, PoolContext* pool,
/* get the tiles out of player's tray and back into the /* get the tiles out of player's tray and back into the
pool */ pool */
if ( !!pool ) { replaceNewTiles( model, pool, turn, &entry.u.move.newTiles);
replaceNewTiles( model, pool, turn, &entry.u.move.newTiles );
}
undoFromMoveInfo( model, turn, blankTile, undoFromMoveInfo( model, turn, blankTile,
&entry.u.move.moveInfo ); &entry.u.move.moveInfo );
@ -1521,6 +1522,19 @@ printMovePost( ModelCtxt* model, XP_U16 moveN, StackEntry* entry,
printString( stream, (XP_UCHAR*)XP_CR ); printString( stream, (XP_UCHAR*)XP_CR );
} /* printMovePost */ } /* printMovePost */
static void
copyStack( ModelCtxt* model, StackCtxt* destStack, const StackCtxt* srcStack )
{
XWStreamCtxt* stream = mem_stream_make( MPPARM(model->vol.mpool)
util_getVTManager(model->vol.util),
NULL, 0, NULL );
stack_writeToStream( (StackCtxt*)srcStack, stream );
stack_loadFromStream( destStack, stream );
stream_destroy( stream );
} /* copyStack */
static ModelCtxt* static ModelCtxt*
makeTmpModel( ModelCtxt* model, XWStreamCtxt* stream, makeTmpModel( ModelCtxt* model, XWStreamCtxt* stream,
MovePrintFuncPre mpf_pre, MovePrintFuncPost mpf_post, MovePrintFuncPre mpf_pre, MovePrintFuncPost mpf_post,
@ -1569,8 +1583,9 @@ scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany,
if ( moveInfo->nTiles == 0 ) { if ( moveInfo->nTiles == 0 ) {
XP_UCHAR* str = util_getUserString( model->vol.util, STR_PASSED ); XP_UCHAR* str = util_getUserString( model->vol.util, STR_PASSED );
*bufLen = XP_STRLEN( str ); XP_U16 len = XP_STRLEN( str );
XP_STRCAT( buf, str ); *bufLen = len;
XP_MEMCPY( buf, str, len+1 ); /* no XP_STRCPY yet */
} else { } else {
XP_U16 score; XP_U16 score;
XP_UCHAR wordBuf[MAX_ROWS+1]; XP_UCHAR wordBuf[MAX_ROWS+1];
@ -1578,9 +1593,14 @@ scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany,
ModelCtxt* tmpModel = makeTmpModel( model, NULL, NULL, NULL, NULL ); ModelCtxt* tmpModel = makeTmpModel( model, NULL, NULL, NULL, NULL );
XP_U16 turn; XP_U16 turn;
XP_S16 moveNum; XP_S16 moveNum = -1;
model_undoLatestMoves( tmpModel, NULL, howMany, &turn, &moveNum ); copyStack( model, tmpModel->vol.stack, model->vol.stack );
if ( !model_undoLatestMoves( tmpModel, NULL, howMany, &turn,
&moveNum ) ) {
XP_ASSERT( 0 );
}
score = figureMoveScore( tmpModel, moveInfo, (EngineCtxt*)NULL, score = figureMoveScore( tmpModel, moveInfo, (EngineCtxt*)NULL,
(XWStreamCtxt*)NULL, XP_TRUE, (XWStreamCtxt*)NULL, XP_TRUE,
@ -1621,7 +1641,8 @@ model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
XP_U16 nTiles; XP_U16 nTiles;
switch ( entry.moveType ) { switch ( entry.moveType ) {
case MOVE_TYPE: case MOVE_TYPE:
scoreLastMove( model, &entry.u.move.moveInfo, nEntries - which, expl, explLen ); scoreLastMove( model, &entry.u.move.moveInfo,
nEntries - which - 1, expl, explLen );
break; break;
case TRADE_TYPE: case TRADE_TYPE:
nTiles = entry.u.trade.oldTiles.nTiles; nTiles = entry.u.trade.oldTiles.nTiles;