add board_canFlip and model_canFlip -- which seem to work though

there's no test that when a single tile is on the board it's not in
the middle.  Sue me.
This commit is contained in:
Andy2 2010-06-30 20:25:34 -07:00
parent 3998a23f84
commit 43c34aa466
5 changed files with 30 additions and 4 deletions

View file

@ -523,6 +523,13 @@ board_getYOffset( const BoardCtxt* board )
return vsd->offset;
} /* board_getYOffset */
XP_Bool
board_canFlip( const BoardCtxt* board )
{
return model_canFlip( board->model, board->selPlayer,
TRAY_REVEALED == board->trayVisState );
}
static XP_U16
adjustOffset( XP_U16 curOffset, XP_S16 zoomBy )
{

View file

@ -78,6 +78,8 @@ void board_reset( BoardCtxt* board );
XP_Bool board_setYOffset( BoardCtxt* board, XP_U16 newOffset );
XP_U16 board_getYOffset( const BoardCtxt* board );
XP_Bool board_canFlip( const BoardCtxt* board );
/* zoomBy: >0: zoom in; < 0: zoom out; 0: query only */
XP_Bool board_zoom( BoardCtxt* board, XP_S16 zoomBy, XP_Bool* canInOut );

View file

@ -480,13 +480,14 @@ undoFromMoveInfo( ModelCtxt* model, XP_U16 turn, Tile blankTile, MoveInfo* mi )
setModelTileRaw( model, col, row, EMPTY_TILE );
notifyBoardListeners( model, turn, col, row, XP_FALSE );
--model->vol.nTilesOnBoard;
if ( IS_BLANK(tile) ) {
tile = blankTile;
}
model_addPlayerTile( model, turn, -1, tile );
}
XP_LOGF( "%s: %d tiles on board", __func__, model->vol.nTilesOnBoard );
adjustScoreForUndone( model, mi, turn );
} /* undoFromMoveInfo */
@ -842,9 +843,9 @@ model_trayContains( ModelCtxt* model, XP_S16 turn, Tile tile )
} /* model_trayContains */
XP_U16
model_getCurrentMoveCount( ModelCtxt* model, XP_S16 turn )
model_getCurrentMoveCount( const ModelCtxt* model, XP_S16 turn )
{
PlayerCtxt* player;
const PlayerCtxt* player;
XP_ASSERT( turn >= 0 );
player = &model->players[turn];
return player->nPending;
@ -1104,6 +1105,14 @@ model_getNMoves( const ModelCtxt* model )
return result;
}
XP_Bool
model_canFlip( const ModelCtxt* model, XP_U16 turn, XP_Bool trayVisible )
{
XP_Bool canFlip = 0 < model->vol.nTilesOnBoard
|| (trayVisible && (0 < model_getCurrentMoveCount( model, turn )));
return canFlip;
}
static void
incrPendingTileCountAt( ModelCtxt* model, XP_U16 col, XP_U16 row )
{
@ -1229,6 +1238,8 @@ commitTurn( ModelCtxt* model, XP_S16 turn, TrayTileSet* newTiles,
setModelTileRaw( model, col, row, tile );
notifyBoardListeners( model, turn, col, row, XP_FALSE );
++model->vol.nTilesOnBoard;
}
(void)getCurrentMoveScoreIfLegal( model, turn, stream, &score );
@ -1247,6 +1258,7 @@ commitTurn( ModelCtxt* model, XP_S16 turn, TrayTileSet* newTiles,
model_addPlayerTile( model, turn, -1, *newTilesP++ );
}
XP_LOGF( "%s: %d tiles on board", __func__, model->vol.nTilesOnBoard );
return score;
} /* commitTurn */

View file

@ -160,7 +160,7 @@ XP_U16 model_numCols( const ModelCtxt* model );
void model_addToCurrentMove( ModelCtxt* model, XP_S16 turn,
XP_U16 col, XP_U16 row,
Tile tile, XP_Bool isBlank );
XP_U16 model_getCurrentMoveCount( ModelCtxt* model, XP_S16 turn );
XP_U16 model_getCurrentMoveCount( const ModelCtxt* model, XP_S16 turn );
void model_getCurrentMoveTile( ModelCtxt* model, XP_S16 turn, XP_S16* index,
Tile* tile, XP_U16* col, XP_U16* row,
@ -190,6 +190,10 @@ void model_makeTurnFromMoveInfo( ModelCtxt* model, XP_U16 playerNum,
void model_resetCurrentTurn( ModelCtxt* model, XP_S16 turn );
XP_S16 model_getNMoves( const ModelCtxt* model );
/* Are there two or more tiles visible */
XP_Bool model_canFlip( const ModelCtxt* model, XP_U16 turn,
XP_Bool trayVisible );
/********************* notification ********************/
typedef void (*BoardListener)(void* data, XP_U16 turn, XP_U16 col,
XP_U16 row, XP_Bool added );

View file

@ -53,6 +53,7 @@ typedef struct ModelVolatiles {
void* trayListenerData;
DictListener dictListenerFunc;
void* dictListenerData;
XP_U16 nTilesOnBoard;
MPSLOT
} ModelVolatiles;