juggle tiles in generated moves (debug only)

Got a report of crashes due to corrupt move records. Given I rarely see
them I wondered if it's because the hint- and robot-generated moves I
work with have tiles in order. So now on debug builds tiles in moves
from those sources are randomly rearranged (as if the user had formed
the word in random order.) The bug isn't showing up, but I figure the
test's worth keeping.
This commit is contained in:
Eric House 2018-02-28 06:44:44 -08:00
parent b3559915e9
commit 760aa3d304
4 changed files with 32 additions and 5 deletions

View file

@ -2177,6 +2177,7 @@ board_requestHint( BoardCtxt* board,
board_popTimerSave( board );
if ( searchComplete && canMove ) {
juggleMoveIfDebug( &newMove );
model_makeTurnFromMoveInfo( model, selPlayer, &newMove);
} else {
result = XP_FALSE;

View file

@ -1120,6 +1120,28 @@ model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum,
return success;
} /* model_makeTurnFromStream */
#ifdef DEBUG
void
juggleMoveIfDebug( MoveInfo* move )
{
XP_U16 nTiles = move->nTiles;
// XP_LOGF( "%s(): move len: %d", __func__, nTiles );
MoveInfoTile tiles[MAX_TRAY_TILES];
XP_MEMCPY( tiles, move->tiles, sizeof(tiles) );
for ( int ii = 0; ii < nTiles; ++ii ) {
int last = nTiles - ii;
int choice = XP_RANDOM() % last;
move->tiles[ii] = tiles[choice];
XP_LOGF( "%s(): setting %d to %d", __func__, ii, choice );
if ( choice != --last ) {
tiles[choice] = tiles[last];
XP_LOGF( "%s(): replacing %d with %d", __func__, choice, last );
}
}
}
#endif
void
model_makeTurnFromMoveInfo( ModelCtxt* model, XP_U16 playerNum,
const MoveInfo* newMove )
@ -1127,11 +1149,8 @@ model_makeTurnFromMoveInfo( ModelCtxt* model, XP_U16 playerNum,
XP_U16 col, row, ii;
XP_U16* other;
const MoveInfoTile* tinfo;
Tile blank;
XP_U16 numTiles;
blank = dict_getBlankTile( model_getDictionary( model ) );
numTiles = newMove->nTiles;
Tile blank = dict_getBlankTile( model_getDictionary( model ) );
XP_U16 numTiles = newMove->nTiles;
col = row = newMove->commonCoord; /* just assign both */
other = newMove->isHorizontal? &col: &row;

View file

@ -221,6 +221,12 @@ XP_Bool model_makeTurnFromStream( ModelCtxt* model, XP_U16 playerNum,
void model_makeTurnFromMoveInfo( ModelCtxt* model, XP_U16 playerNum,
const MoveInfo* newMove );
#ifdef DEBUG
void juggleMoveIfDebug( MoveInfo* move );
#else
# define juggleMoveIfDebug(newMove)
#endif
void model_resetCurrentTurn( ModelCtxt* model, XP_S16 turn );
XP_S16 model_getNMoves( const ModelCtxt* model );

View file

@ -929,6 +929,7 @@ makeRobotMove( ServerCtxt* server )
/* if canMove is false, this is a fake move, a pass */
if ( canMove || NPASSES_OK(server) ) {
juggleMoveIfDebug( &newMove );
model_makeTurnFromMoveInfo( model, turn, &newMove );
XP_LOGF( "%s: robot making %d tile move", __func__, newMove.nTiles );