- add debug strings

This commit is contained in:
Antoine Fraboulet 2006-08-11 22:13:02 +00:00
parent f9af9493d2
commit 9f86b53021
3 changed files with 101 additions and 72 deletions

View file

@ -78,6 +78,7 @@ int Game::helperPlayRound(const Round &iRound)
m_history.setCurrentRack(getCurrentPlayer().getLastRack());
m_history.playRound(m_currPlayer, m_history.getSize(), iRound);
debug(" helper: %d points\n",iRound.getPoints());
m_points += iRound.getPoints();
// Before updating the bag and the board, if we are playing a "joker game",
@ -141,7 +142,9 @@ int Game::helperPlayRound(const Round &iRound)
m_bag.takeTile(Tile::Joker());
}
else
{
m_bag.takeTile(iRound.getTile(i));
}
}
}
m_board.addRound(*m_dic, iRound);
@ -528,11 +531,16 @@ int Game::checkPlayedWord(const wstring &iCoord,
oRound.init();
oRound.accessCoord().setFromString(iCoord);
if (!oRound.getCoord().isValid())
{
debug("game: incorrect coordinates\n");
return 2;
}
/* Check the existence of the word */
if (Dic_search_word(*m_dic, iWord.c_str()) == 0)
{
return 3;
}
/* Set the word */
// TODO: make this a Round_ function (Round_setwordfromchar for example)

View file

@ -97,82 +97,93 @@ Game * Game::load(FILE *fin, const Dictionary& iDic)
Game* Game::gameLoadFormat_14(FILE *fin, const Dictionary& iDic)
{
Tile tile;
char buff[4096];
char rack[20];
char word[20];
char pos [5];
char delim[]=" \t\n\012\015";
char *token;
Game *pGame = NULL;
int ret = 0;
int line = 0;
Tile tile;
char buff[4096];
char rack[20];
char word[20];
char pos [5];
char delim[]=" \t\n\012\015";
char *token;
Game *pGame = NULL;
debug("Game::gameLoadFormat_14\n");
pGame = GameFactory::Instance()->createTraining(iDic);
pGame->start();
/* rack word ?bonus pts coord */
/* EUOFMIE FUMEE * 26 H 4 */
/* read all turns until total */
while (fgets(buff, sizeof(buff), fin))
{
line++;
token = strtok(buff, delim);
if (token != NULL)
{
debug("======== \n");
if (strcmp(token, "total") == 0)
{
break;
}
debug("Game::gameLoadFormat_14\n");
/* rack */
strncpy(rack, token, sizeof(rack));
static_cast<Training*>(pGame)->setRack(RACK_MANUAL, false,
convertToWc(rack));
debug("load: %8s ", rack);
/* word */
token = strtok(NULL, delim);
if (!token || strcmp(token, "total") == 0)
{
break;
}
pGame = GameFactory::Instance()->createTraining(iDic);
pGame->start();
strncpy(word, token, sizeof(word));
debug(" %12s ", word);
/* bonus */
if ((token = strtok(NULL, delim)) == NULL)
break;
/* points */
if (token[0] == '*')
{
debug("%s\t", token);
if ((token = strtok(NULL, delim)) == NULL)
break;
}
else
{
debug(" \t");
}
/* rack word ?bonus pts coord */
/* EUOFMIE FUMEE * 26 H 4 */
/* pos 1 */
if ((token = strtok(NULL, delim)) == NULL)
break;
/* read all turns until total */
while (fgets(buff, sizeof(buff), fin))
{
token = strtok(buff, delim);
if (token != NULL)
{
if (strcmp(token, "total") == 0)
{
break;
}
//debug("(%s ", token);
strncpy(pos, token, sizeof(pos));
/* rack */
strncpy(rack, token, sizeof(rack));
static_cast<Training*>(pGame)->setRack(RACK_MANUAL, false,
convertToWc(rack));
debug("%s ", rack);
/* pos 2 */
if ((token = strtok(NULL, delim)) == NULL)
break;
/* word */
token = strtok(NULL, delim);
if (!token || strcmp(token, "total") == 0)
{
break;
}
//debug("%s)", token);
strncat(pos, token, sizeof(pos));
debug("%s\n", pos);
strncpy(word, token, sizeof(word));
debug("\t%s ", word);
/* bonus */
if ((token = strtok(NULL, delim)) == NULL)
break;
/* points */
if (token[0] == '*')
{
debug("%s\t", token);
if ((token = strtok(NULL, delim)) == NULL)
break;
}
/* pos 1 */
if ((token = strtok(NULL, delim)) == NULL)
break;
debug("(%s ", token);
strncpy(pos, token, sizeof(pos));
/* pos 2 */
if ((token = strtok(NULL, delim)) == NULL)
break;
debug("%s)", token);
strncat(pos, token, sizeof(pos));
debug("%s\n", pos);
debug(" play %s %s\n", pos, word);
pGame->play(convertToWc(pos), convertToWc(word));
}
}
return pGame;
if ((ret = pGame->play(convertToWc(pos), convertToWc(word))))
{
debug("loading error %d on line %d\n",ret,line);
GameFactory::Instance()->releaseGame(*pGame);
return NULL;
}
}
}
return pGame;
}

View file

@ -103,21 +103,31 @@ int Training::play(const wstring &iCoord, const wstring &iWord)
{
/* Perform all the validity checks, and fill a round */
Round round;
int res = checkPlayedWord(iCoord, iWord, round);
if (res != 0)
{
debug("check returned with an error %d\n",res);
return res;
}
/* Update the rack and the score of the current player */
debug("play: %s %s %d\n",
convertToMb(round.getWord()).c_str(),
convertToMb(round.getCoord().toString()).c_str(),
round.getPoints());
m_players[m_currPlayer]->addPoints(round.getPoints());
// see game.cpp::helperPlayRound():99 comment
m_players[m_currPlayer]->endTurn(round, m_history.getSize());
/* Everything is OK, we can play the word */
helperPlayRound(round);
if (helperPlayRound(round))
{
debug("play: error during play\n");
}
/* Next turn */
// XXX: Should it be done by the interface instead?
endTurn();
return 0;