Simplify slightly the Round API

This commit is contained in:
Olivier Teulière 2012-02-18 23:13:02 +01:00
parent 0be2769dfa
commit b855c5f64e
4 changed files with 18 additions and 45 deletions

View file

@ -63,11 +63,10 @@ void BoardSearch::search(Rack &iRack, Results &oResults, Coord::Direction iDir)
vector<Tile> rackTiles;
iRack.getTiles(rackTiles);
vector<Tile>::const_iterator it;
Round partialWord;
for (int row = 1; row <= BOARD_DIM; row++)
{
partialWord.init();
Round partialWord;
partialWord.accessCoord().setDir(iDir);
partialWord.accessCoord().setRow(row);
int lastanchor = 0;
@ -150,7 +149,7 @@ void BoardSearch::leftPart(Rack &iRack, Round &ioPartialWord,
leftPart(iRack, ioPartialWord, oResults,
succ, iRow, iAnchor, iLimit - 1);
ioPartialWord.accessCoord().setCol(ioPartialWord.getCoord().getCol() + 1);
ioPartialWord.removeRightToRack(l, false);
ioPartialWord.removeRight();
iRack.add(l);
}
if (hasJokerInRack)
@ -161,7 +160,7 @@ void BoardSearch::leftPart(Rack &iRack, Round &ioPartialWord,
leftPart(iRack, ioPartialWord, oResults,
succ, iRow, iAnchor, iLimit - 1);
ioPartialWord.accessCoord().setCol(ioPartialWord.getCoord().getCol() + 1);
ioPartialWord.removeRightToRack(l, true);
ioPartialWord.removeRight();
iRack.add(Tile::Joker());
}
}
@ -198,7 +197,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord,
ioPartialWord.addRightFromRack(l, false);
extendRight(iRack, ioPartialWord, oResults,
succ, iRow, iCol + 1, iAnchor);
ioPartialWord.removeRightToRack(l, false);
ioPartialWord.removeRight();
iRack.add(l);
}
if (hasJokerInRack)
@ -207,7 +206,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord,
ioPartialWord.addRightFromRack(l, true);
extendRight(iRack, ioPartialWord, oResults,
succ, iRow, iCol + 1, iAnchor);
ioPartialWord.removeRightToRack(l, true);
ioPartialWord.removeRight();
iRack.add(Tile::Joker());
}
}
@ -224,7 +223,7 @@ void BoardSearch::extendRight(Rack &iRack, Round &ioPartialWord,
ioPartialWord.addRightFromBoard(l);
extendRight(iRack, ioPartialWord,
oResults, succ, iRow, iCol + 1, iAnchor);
ioPartialWord.removeRightToBoard(l);
ioPartialWord.removeRight();
// The letter will be present only once in the dictionary,
// so we can stop looping
break;

View file

@ -513,7 +513,7 @@ int Game::checkPlayedWord(const wstring &iCoord,
return 1;
// Init the round with the given coordinates
oRound.init();
oRound = Round();
oRound.accessCoord().setFromString(iCoord);
if (!oRound.getCoord().isValid())
{

View file

@ -35,24 +35,10 @@ INIT_LOGGER(game, Round);
#define FROMRACK 0x2
#define JOKER 0x4
#define __UNUSED__ __attribute__((unused))
Round::Round()
: m_coord(1, 1, Coord::HORIZONTAL), m_points(0), m_bonus(false)
{
init();
}
void Round::init()
{
m_word.clear();
m_tileOrigin.clear();
m_coord.setRow(1);
m_coord.setCol(1);
m_coord.setDir(Coord::HORIZONTAL);
m_points = 0;
m_bonus = false;
}
@ -105,24 +91,16 @@ bool Round::isPlayedFromRack(unsigned int iIndex) const
}
void Round::addRightFromBoard(Tile c)
void Round::addRightFromBoard(const Tile &iTile)
{
m_word.push_back(c);
m_word.push_back(iTile);
m_tileOrigin.push_back(FROMBOARD);
}
void Round::removeRightToBoard(Tile __UNUSED__ c)
void Round::addRightFromRack(const Tile &iTile, bool iJoker)
{
// c is unused.
m_word.pop_back();
m_tileOrigin.pop_back();
}
void Round::addRightFromRack(Tile c, bool iJoker)
{
m_word.push_back(c);
m_word.push_back(iTile);
char origin = FROMRACK;
if (iJoker)
{
@ -132,13 +110,13 @@ void Round::addRightFromRack(Tile c, bool iJoker)
}
void Round::removeRightToRack(Tile __UNUSED__ c, bool __UNUSED__ iJoker)
void Round::removeRight()
{
// c is unused.
m_word.pop_back();
m_tileOrigin.pop_back();
}
wstring Round::getWord() const
{
wstring s;
@ -153,6 +131,7 @@ wstring Round::getWord() const
return s;
}
wstring Round::toString() const
{
wostringstream oss;

View file

@ -41,19 +41,14 @@ class Round
DEFINE_LOGGER();
public:
/*************************
*
*************************/
Round();
void init();
/*************************
*
*************************/
void addRightFromBoard(Tile);
void removeRightToBoard(Tile);
void addRightFromRack(Tile, bool);
void removeRightToRack(Tile, bool);
void addRightFromBoard(const Tile &iTile);
void addRightFromRack(const Tile &iTile, bool iJoker);
void removeRight();
/*************************
* General setters