Simplify the handling of jokers in the Round class.

This also fixes a very old (but minor) bug: when a word containing a
joker was played "manually" (i.e. not via a round generated by the
Results class but via the Game::checkPlayedWord() method), subsequent
search results using this joker on the board would display it as a
joker, not as a normal tile.
This commit is contained in:
Olivier Teulière 2012-02-19 10:31:05 +01:00
parent b855c5f64e
commit 6e2c665bdf
6 changed files with 40 additions and 68 deletions

View file

@ -536,11 +536,6 @@ int Game::checkPlayedWord(const wstring &iCoord,
tiles.push_back(Tile(iWord[i]));
}
oRound.setWord(tiles);
for (unsigned int i = 0; i < iWord.size(); i++)
{
if (islower(iWord[i]))
oRound.setJoker(i);
}
// Check the word position, compute its points,
// and specify the origin of each letter (board or rack)

View file

@ -119,12 +119,6 @@ void GameMoveCmd::playRound()
bag.replaceTile(Tile::Joker());
bag.takeTile(t);
m_round.setTile(i, t);
// FIXME: This shouldn't be necessary, this is only
// needed because of the stupid way of handling jokers in
// rounds
// This is also needed for the unplayRound() method
// to work correctly
m_round.setJoker(i, false);
}
// In a joker game we should have only 1 joker in the rack

View file

@ -31,11 +31,6 @@
INIT_LOGGER(game, Round);
#define FROMBOARD 0x1
#define FROMRACK 0x2
#define JOKER 0x4
Round::Round()
: m_coord(1, 1, Coord::HORIZONTAL), m_points(0), m_bonus(false)
{
@ -46,36 +41,25 @@ void Round::setWord(const vector<Tile> &iTiles)
{
m_word = iTiles;
// XXX: always from rack?
m_tileOrigin = vector<char>(iTiles.size(), FROMRACK);
m_rackOrigin = vector<bool>(iTiles.size(), true);
}
void Round::setFromRack(unsigned int iIndex)
{
m_tileOrigin[iIndex] &= ~FROMBOARD;
m_tileOrigin[iIndex] |= FROMRACK;
m_rackOrigin[iIndex] = true;
}
void Round::setFromBoard(unsigned int iIndex)
{
m_tileOrigin[iIndex] &= ~FROMRACK;
m_tileOrigin[iIndex] |= FROMBOARD;
}
void Round::setJoker(unsigned int iIndex, bool value)
{
if (value)
m_tileOrigin[iIndex] |= JOKER;
else
m_tileOrigin[iIndex] &= ~JOKER;
m_rackOrigin[iIndex] = false;
}
bool Round::isJoker(unsigned int iIndex) const
{
return m_tileOrigin[iIndex] & JOKER;
return m_word[iIndex].isJoker();
}
@ -87,33 +71,33 @@ const Tile& Round::getTile(unsigned int iIndex) const
bool Round::isPlayedFromRack(unsigned int iIndex) const
{
return m_tileOrigin[iIndex] & FROMRACK;
return m_rackOrigin[iIndex];
}
void Round::addRightFromBoard(const Tile &iTile)
{
m_word.push_back(iTile);
m_tileOrigin.push_back(FROMBOARD);
// The call to toUpper() is necessary to avoid that a joker
// on the board appears as a joker in the Round
m_word.push_back(iTile.toUpper());
m_rackOrigin.push_back(false);
}
void Round::addRightFromRack(const Tile &iTile, bool iJoker)
{
m_word.push_back(iTile);
char origin = FROMRACK;
if (iJoker)
{
origin |= JOKER;
}
m_tileOrigin.push_back(origin);
m_word.push_back(iTile.toLower());
else
m_word.push_back(iTile);
m_rackOrigin.push_back(true);
}
void Round::removeRight()
{
m_word.pop_back();
m_tileOrigin.pop_back();
m_rackOrigin.pop_back();
}

View file

@ -59,7 +59,6 @@ public:
void setWord(const vector<Tile> &iTiles);
void setFromRack(unsigned int iIndex);
void setFromBoard(unsigned int iIndex);
void setJoker(unsigned int iIndex, bool value = true);
/*************************
* General getters
@ -85,7 +84,7 @@ public:
private:
vector<Tile> m_word;
vector<char> m_tileOrigin;
vector<bool> m_rackOrigin;
Coord m_coord;
int m_points;
bool m_bonus;

View file

@ -130,13 +130,13 @@ commande> a gd # r2
commande> r
commande> a r
1: SaUGRENU * 82 E4
2: eNjUGUES * 66 D8
2: ENjUGUES * 66 D8
3: GUEUSANt * 66 11C
4: NUaGEUSe * 66 D1
5: ENjUGUeS * 64 D2
6: GUEUSeNt * 64 D3
7: GUeUSENt * 64 D6
8: NUaGeUSE * 64 D4
4: NUaGEUSE * 66 D1
5: ENjUGUES * 64 D2
6: GUEUSENt * 64 D3
7: GUEUSENt * 64 D6
8: NUaGEUSE * 64 D4
9: GUeUSENT * 62 F1
10: GUEUSaNT * 60 F1
commande> a gd # r3

View file

@ -863,39 +863,39 @@ commande> a r 50
15: Es 5 G7
16: Ex 5 G7
17: aIE 2 8G
18: buE 2 7G
19: duE 2 7G
18: bUE 2 7G
19: dUE 2 7G
20: EpI 2 8F
21: Eu 2 7G
22: Eue 2 7G
23: euE 2 7G
24: Euh 2 7G
25: Eus 2 7G
26: Eut 2 7G
27: Eux 2 7G
28: fEu 2 7F
21: EU 2 7G
22: EUe 2 7G
23: eUE 2 7G
24: EUh 2 7G
25: EUs 2 7G
26: EUt 2 7G
27: EUx 2 7G
28: fEU 2 7F
29: fIE 2 8G
30: guE 2 7G
31: hEu 2 7F
30: gUE 2 7G
31: hEU 2 7F
32: hIE 2 8G
33: huE 2 7G
33: hUE 2 7G
34: IdE 2 8H
35: IlE 2 8H
36: IpE 2 8H
37: IrE 2 8H
38: IvE 2 8H
39: IxE 2 8H
40: jEu 2 7F
40: jEU 2 7F
41: lEI 2 8F
42: lEu 2 7F
42: lEU 2 7F
43: lIE 2 8G
44: luE 2 7G
44: lUE 2 7G
45: mIE 2 8G
46: muE 2 7G
46: mUE 2 7G
47: nIE 2 8G
48: nuE 2 7G
48: nUE 2 7G
49: oIE 2 8G
50: pEu 2 7F
50: pEU 2 7F
commande> q
fin du mode entraînement
commande> q