add some consts.

This commit is contained in:
ehouse 2008-05-06 12:49:37 +00:00
parent 6c81a63fce
commit ebad668227
9 changed files with 59 additions and 54 deletions

View file

@ -60,8 +60,8 @@ typedef XP_U32 CrossBits;
typedef struct Crosscheck { CrossBits bits[2]; } Crosscheck;
struct EngineCtxt {
ModelCtxt* model;
DictionaryCtxt* dict;
const ModelCtxt* model;
const DictionaryCtxt* dict;
XW_UtilCtxt* util;
Engine_rack rack;
@ -99,7 +99,8 @@ struct EngineCtxt {
static void findMovesOneRow( EngineCtxt* engine );
static Tile localGetBoardTile( EngineCtxt* engine, XP_U16 col,
XP_U16 row, XP_Bool substBlank );
static array_edge* edge_with_tile( DictionaryCtxt* dict, array_edge* from, Tile tile );
static array_edge* edge_with_tile( const DictionaryCtxt* dict,
array_edge* from, Tile tile );
static XP_Bool scoreQualifies( EngineCtxt* engine, XP_U16 score );
static void findMovesForAnchor( EngineCtxt* engine, XP_S16* prevAnchor,
XP_U16 col, XP_U16 row ) ;
@ -107,9 +108,9 @@ static void figureCrosschecks( EngineCtxt* engine, XP_U16 col,
XP_U16 row, XP_U16* scoreP,
Crosscheck* check );
static XP_Bool isAnchorSquare( EngineCtxt* engine, XP_U16 col, XP_U16 row );
static array_edge* follow( DictionaryCtxt* dict, array_edge* in );
static array_edge* edge_from_tile( DictionaryCtxt* dict, array_edge* from,
Tile tile );
static array_edge* follow( const DictionaryCtxt* dict, array_edge* in );
static array_edge* edge_from_tile( const DictionaryCtxt* dict,
array_edge* from, Tile tile );
static void leftPart( EngineCtxt* engine, Tile* tiles, XP_U16 tileLength,
array_edge* edge, XP_U16 limit, XP_U16 firstCol,
XP_U16 anchorCol, XP_U16 row );
@ -379,8 +380,8 @@ chooseMove( EngineCtxt* engine, PossibleMove** move )
* filled in in *newMove.
*/
XP_Bool
engine_findMove( EngineCtxt* engine, ModelCtxt* model,
DictionaryCtxt* dict, const Tile* tiles,
engine_findMove( EngineCtxt* engine, const ModelCtxt* model,
const DictionaryCtxt* dict, const Tile* tiles,
XP_U16 nTiles,
#ifdef XWFEATURE_SEARCHLIMIT
BdHintLimits* searchLimits,
@ -579,8 +580,8 @@ findMovesOneRow( EngineCtxt* engine )
} /* findMovesOneRow */
static XP_Bool
lookup( DictionaryCtxt* dict, array_edge* edge, Tile* buf, XP_U16 tileIndex,
XP_U16 length )
lookup( const DictionaryCtxt* dict, array_edge* edge, Tile* buf,
XP_U16 tileIndex, XP_U16 length )
{
while ( edge != NULL ) {
Tile targetTile = buf[tileIndex];
@ -611,7 +612,7 @@ figureCrosschecks( EngineCtxt* engine, XP_U16 x, XP_U16 y, XP_U16* scoreP,
Tile tiles[MAX_COLS];
XP_U16 tilesAfter;
XP_U16 checkScore = 0;
DictionaryCtxt* dict = engine->dict;
const DictionaryCtxt* dict = engine->dict;
if ( localGetBoardTile( engine, x, y, XP_FALSE ) == EMPTY_TILE ) {
@ -802,7 +803,6 @@ findMovesForAnchor( EngineCtxt* engine, XP_S16* prevAnchor,
array_edge* edge;
array_edge* topEdge;
Tile tiles[MAX_ROWS];
XP_S16 tileLength = 0;
hiliteForAnchor( engine, col, row );
@ -826,7 +826,7 @@ findMovesForAnchor( EngineCtxt* engine, XP_S16* prevAnchor,
edge = consumeFromLeft( engine, topEdge, col, row );
}
DEBUG_ASSIGN(engine->curLimit, 0);
extendRight( engine, tiles, tileLength, edge,
extendRight( engine, tiles, 0, edge,
XP_FALSE, // can't accept without the anchor square
col-limit, col, row );
@ -914,7 +914,7 @@ extendRight( EngineCtxt* engine, Tile* tiles, XP_U16 tileLength,
XP_U16 firstCol, XP_U16 col, XP_U16 row )
{
Tile tile;
DictionaryCtxt* dict = engine->dict;
const DictionaryCtxt* dict = engine->dict;
if ( col == engine->numCols ) { /* we're off the board */
goto check_exit;
@ -1208,7 +1208,7 @@ scoreQualifies( EngineCtxt* engine, XP_U16 score )
} /* scoreQualifies */
static array_edge*
edge_with_tile( DictionaryCtxt* dict, array_edge* from, Tile tile )
edge_with_tile( const DictionaryCtxt* dict, array_edge* from, Tile tile )
{
for ( ; ; ) {
Tile candidate = EDGETILE(dict,from);
@ -1232,7 +1232,7 @@ edge_with_tile( DictionaryCtxt* dict, array_edge* from, Tile tile )
} /* edge_with_tile */
static unsigned long
index_from( DictionaryCtxt* dict, array_edge* p_edge )
index_from( const DictionaryCtxt* dict, array_edge* p_edge )
{
unsigned long result;
@ -1260,7 +1260,7 @@ index_from( DictionaryCtxt* dict, array_edge* p_edge )
} /* index_from */
static array_edge*
follow( DictionaryCtxt* dict, array_edge* in )
follow( const DictionaryCtxt* dict, array_edge* in )
{
XP_U32 index = index_from( dict, in );
array_edge* result = index > 0?
@ -1269,7 +1269,7 @@ follow( DictionaryCtxt* dict, array_edge* in )
} /* follow */
static array_edge*
edge_from_tile( DictionaryCtxt* dict, array_edge* from, Tile tile )
edge_from_tile( const DictionaryCtxt* dict, array_edge* from, Tile tile )
{
array_edge* edge = edge_with_tile( dict, from, tile );
if ( edge != NULL ) {

View file

@ -49,8 +49,8 @@ void engine_reset( EngineCtxt* ctxt );
void engine_destroy( EngineCtxt* ctxt );
#define NO_SCORE_LIMIT 10000 /* for targetScore */
XP_Bool engine_findMove( EngineCtxt* ctxt, ModelCtxt* model,
DictionaryCtxt* dict, const Tile* tiles,
XP_Bool engine_findMove( EngineCtxt* ctxt, const ModelCtxt* model,
const DictionaryCtxt* dict, const Tile* tiles,
XP_U16 nTiles,
#ifdef XWFEATURE_SEARCHLIMIT
BdHintLimits* boardLimits,

View file

@ -50,7 +50,8 @@ static void notifyBoardListeners( ModelCtxt* model, XP_U16 turn,
XP_U16 col, XP_U16 row, XP_Bool added );
static void notifyTrayListeners( ModelCtxt* model, XP_U16 turn,
XP_S16 index1, XP_S16 index2 );
static CellTile getModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row );
static CellTile getModelTileRaw( const ModelCtxt* model, XP_U16 col,
XP_U16 row );
static void setModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row,
CellTile tile );
static void assignPlayerTiles( ModelCtxt* model, XP_S16 turn,
@ -280,12 +281,12 @@ model_getDictionary( ModelCtxt* model )
} /* model_getDictionary */
static XP_Bool
getPendingTileFor( ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row,
getPendingTileFor( const ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row,
CellTile* cellTile )
{
XP_Bool found = XP_FALSE;
PlayerCtxt* player;
PendingTile* pendings;
const PlayerCtxt* player;
const PendingTile* pendings;
XP_U16 i;
player = &model->players[turn];
@ -305,8 +306,8 @@ getPendingTileFor( ModelCtxt* model, XP_U16 turn, XP_U16 col, XP_U16 row,
} /* getPendingTileFor */
XP_Bool
model_getTile( ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool getPending,
XP_S16 turn, Tile* tileP, XP_Bool* isBlank,
model_getTile( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool getPending, XP_S16 turn, Tile* tileP, XP_Bool* isBlank,
XP_Bool* pendingP, XP_Bool* recentP )
{
CellTile cellTile = getModelTileRaw( model, col, row );
@ -456,7 +457,7 @@ setModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row, CellTile tile )
} /* model_setTile */
static CellTile
getModelTileRaw( ModelCtxt* model, XP_U16 col, XP_U16 row )
getModelTileRaw( const ModelCtxt* model, XP_U16 col, XP_U16 row )
{
XP_ASSERT( col < MAX_COLS );
XP_ASSERT( row < MAX_ROWS );
@ -1378,13 +1379,13 @@ model_getNumTilesTotal( ModelCtxt* model, XP_S16 turn )
} /* model_getNumTilesTotal */
XP_U16
model_numRows( ModelCtxt* model )
model_numRows( const ModelCtxt* model )
{
return model->nRows;
} /* model_numRows */
XP_U16
model_numCols( ModelCtxt* model )
model_numCols( const ModelCtxt* model )
{
return model->nCols;
} /* model_numCols */

View file

@ -110,7 +110,7 @@ void model_setNPlayers( ModelCtxt* model, XP_U16 numPlayers );
void model_setDictionary( ModelCtxt* model, DictionaryCtxt* dict );
DictionaryCtxt* model_getDictionary( ModelCtxt* model );
XP_Bool model_getTile( ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool model_getTile( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool getPending, XP_S16 turn,
Tile* tile, XP_Bool* isBlank,
XP_Bool* isPending, XP_Bool* isRecent );
@ -148,8 +148,8 @@ XP_S16 model_trayContains( ModelCtxt* model, XP_S16 turn, Tile tile );
/* void model_setTile( ModelCtxt* model, XP_U16 col, XP_U16 row, */
/* Tile tile, XP_Bool isBlank ); */
XP_U16 model_numRows( ModelCtxt* model );
XP_U16 model_numCols( ModelCtxt* model );
XP_U16 model_numRows( const ModelCtxt* model );
XP_U16 model_numCols( const ModelCtxt* model );
/* XP_U16 model_numTilesCurrentTray( ModelCtxt* model ); */
/* Tile model_currentTrayTile( ModelCtxt* model, XP_U16 index ); */
@ -233,7 +233,7 @@ void model_figureFinalScores( ModelCtxt* model, XP_S16* scores,
XP_S16* tilePenalties );
/* figureMoveScore is meant only for the engine's use */
XP_U16 figureMoveScore( ModelCtxt* model, MoveInfo* moveInfo,
XP_U16 figureMoveScore( const ModelCtxt* model, MoveInfo* moveInfo,
EngineCtxt* engine, XWStreamCtxt* stream,
WordNotifierInfo* notifyInfo, XP_UCHAR* mainWord );

View file

@ -31,10 +31,11 @@ extern "C" {
/****************************** prototypes ******************************/
static XP_Bool isLegalMove( ModelCtxt* model, MoveInfo* moves, XP_Bool silent );
static XP_U16 word_multiplier( ModelCtxt* model, XP_U16 col, XP_U16 row );
static XP_U16 find_end( ModelCtxt* model, XP_U16 col, XP_U16 row,
static XP_U16 word_multiplier( const ModelCtxt* model,
XP_U16 col, XP_U16 row );
static XP_U16 find_end( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool isHorizontal );
static XP_U16 find_start( ModelCtxt* model, XP_U16 col, XP_U16 row,
static XP_U16 find_start( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool isHorizontal );
static XP_S16 checkScoreMove( ModelCtxt* model, XP_S16 turn,
EngineCtxt* engine, XWStreamCtxt* stream,
@ -43,7 +44,7 @@ static XP_S16 checkScoreMove( ModelCtxt* model, XP_S16 turn,
/* EngineCtxt* engine, */
/* XP_Bool silent, short moveMultiplier, */
/* WordNotifierInfo* notifyInfo ); */
static XP_U16 scoreWord( ModelCtxt* model, MoveInfo* movei,
static XP_U16 scoreWord( const ModelCtxt* model, MoveInfo* movei,
EngineCtxt* engine, XWStreamCtxt* stream,
WordNotifierInfo* notifyInfo, XP_UCHAR* mainWord );
@ -69,7 +70,7 @@ static void wordScoreFormatterFinish( WordScoreFormatter* fmtr, Tile* word,
XWStreamCtxt* stream, XP_UCHAR* mainWord );
static void formatWordScore( XWStreamCtxt* stream, XP_U16 wordScore,
XP_U16 moveMultiplier );
static void formatSummary( XWStreamCtxt* stream, ModelCtxt* model,
static void formatSummary( XWStreamCtxt* stream, const ModelCtxt* model,
XP_U16 score );
@ -313,7 +314,7 @@ normalizeMoves( ModelCtxt* model, XP_S16 turn, XP_Bool isHorizontal,
} /* normalizeMoves */
static XP_Bool
modelIsEmptyAt( ModelCtxt* model, XP_U16 col, XP_U16 row )
modelIsEmptyAt( const ModelCtxt* model, XP_U16 col, XP_U16 row )
{
Tile tile;
XP_Bool ignore;
@ -443,9 +444,9 @@ isLegalMove( ModelCtxt* model, MoveInfo* mInfo, XP_Bool silent )
} /* isLegalMove */
XP_U16
figureMoveScore( ModelCtxt* model, MoveInfo* moveInfo, EngineCtxt* engine,
XWStreamCtxt* stream, WordNotifierInfo* notifyInfo,
XP_UCHAR* mainWord )
figureMoveScore( const ModelCtxt* model, MoveInfo* moveInfo,
EngineCtxt* engine, XWStreamCtxt* stream,
WordNotifierInfo* notifyInfo, XP_UCHAR* mainWord )
{
XP_U16 col, row;
XP_U16* incr;
@ -527,7 +528,7 @@ figureMoveScore( ModelCtxt* model, MoveInfo* moveInfo, EngineCtxt* engine,
} /* figureMoveScore */
static XP_U16
word_multiplier( ModelCtxt* model, XP_U16 col, XP_U16 row )
word_multiplier( const ModelCtxt* model, XP_U16 col, XP_U16 row )
{
XWBonusType bonus = util_getSquareBonus( model->vol.util, model, col, row );
switch ( bonus ) {
@ -541,7 +542,7 @@ word_multiplier( ModelCtxt* model, XP_U16 col, XP_U16 row )
} /* word_multiplier */
static XP_U16
tile_multiplier( ModelCtxt* model, XP_U16 col, XP_U16 row )
tile_multiplier( const ModelCtxt* model, XP_U16 col, XP_U16 row )
{
XWBonusType bonus = util_getSquareBonus( model->vol.util, model,
col, row );
@ -556,7 +557,7 @@ tile_multiplier( ModelCtxt* model, XP_U16 col, XP_U16 row )
} /* tile_multiplier */
static XP_U16
scoreWord( ModelCtxt* model, MoveInfo* movei, /* new tiles */
scoreWord( const ModelCtxt* model, MoveInfo* movei, /* new tiles */
EngineCtxt* engine,/* for crosswise caching */
XWStreamCtxt* stream,
WordNotifierInfo* notifyInfo,
@ -703,7 +704,8 @@ scoreWord( ModelCtxt* model, MoveInfo* movei, /* new tiles */
} /* scoreWord */
static XP_U16
find_start( ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool isHorizontal )
find_start( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool isHorizontal )
{
XP_U16* incr = isHorizontal? &col: &row;
@ -720,7 +722,8 @@ find_start( ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool isHorizontal )
} /* find_start */
static XP_U16
find_end( ModelCtxt* model, XP_U16 col, XP_U16 row, XP_Bool isHorizontal )
find_end( const ModelCtxt* model, XP_U16 col, XP_U16 row,
XP_Bool isHorizontal )
{
XP_U16* incr = isHorizontal? &col: &row;
XP_U16 limit = isHorizontal? MAX_COLS-1:MAX_ROWS-1;
@ -835,7 +838,7 @@ formatWordScore( XWStreamCtxt* stream, XP_U16 wordScore,
} /* formatWordScore */
static void
formatSummary( XWStreamCtxt* stream, ModelCtxt* model, XP_U16 score )
formatSummary( XWStreamCtxt* stream, const ModelCtxt* model, XP_U16 score )
{
XP_UCHAR buf[60];
XP_SNPRINTF(buf, sizeof(buf),

View file

@ -105,7 +105,8 @@ typedef struct UtilVtable {
XP_PlayerAddr channelNo );
#endif
XWBonusType (*m_util_getSquareBonus)( XW_UtilCtxt* uc, ModelCtxt* model,
XWBonusType (*m_util_getSquareBonus)( XW_UtilCtxt* uc,
const ModelCtxt* model,
XP_U16 col, XP_U16 row );
void (*m_util_userError)( XW_UtilCtxt* uc, UtilErrID id );

View file

@ -625,7 +625,7 @@ linux_util_makeEmptyDict( XW_UtilCtxt* uctx )
static XWBonusType
linux_util_getSquareBonus( XW_UtilCtxt* XP_UNUSED(uc),
ModelCtxt* XP_UNUSED(model),
const ModelCtxt* XP_UNUSED(model),
XP_U16 col, XP_U16 row )
{
XP_U16 index;

View file

@ -104,7 +104,7 @@ static void palm_util_userError( XW_UtilCtxt* uc, UtilErrID id );
static XP_Bool palm_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
XWStreamCtxt* stream );
static XWBonusType palm_util_getSquareBonus( XW_UtilCtxt* uc,
ModelCtxt* model,
const ModelCtxt* model,
XP_U16 col, XP_U16 row );
static XP_S16 palm_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
XP_U16 playerNum, const XP_UCHAR4* texts,
@ -3721,7 +3721,7 @@ palm_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
} /* palm_util_userQuery */
static XWBonusType
palm_util_getSquareBonus( XW_UtilCtxt* uc, ModelCtxt* model,
palm_util_getSquareBonus( XW_UtilCtxt* uc, const ModelCtxt* model,
XP_U16 col, XP_U16 row )
{
PalmAppGlobals* globals = (PalmAppGlobals*)uc->closure;

View file

@ -92,7 +92,7 @@ static void ce_util_userError( XW_UtilCtxt* uc, UtilErrID id );
static XP_Bool ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id,
XWStreamCtxt* stream );
static XWBonusType ce_util_getSquareBonus( XW_UtilCtxt* uc,
ModelCtxt* model,
const ModelCtxt* model,
XP_U16 col, XP_U16 row );
static XP_S16 ce_util_userPickTile( XW_UtilCtxt* uc, const PickInfo* pi,
XP_U16 playerNum,
@ -2739,7 +2739,7 @@ ce_util_userQuery( XW_UtilCtxt* uc, UtilQueryID id, XWStreamCtxt* stream )
} /* ce_util_userQuery */
static XWBonusType
ce_util_getSquareBonus( XW_UtilCtxt* uc, ModelCtxt* XP_UNUSED(model),
ce_util_getSquareBonus( XW_UtilCtxt* uc, const ModelCtxt* XP_UNUSED(model),
XP_U16 col, XP_U16 row )
{
XP_U16 index;