mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-18 10:26:15 +01:00
New utility methods to get the lowercase (joker) or uppercase (no joker) variant of a tile
This commit is contained in:
parent
0d45fc6227
commit
0be2769dfa
5 changed files with 32 additions and 9 deletions
17
dic/tile.cpp
17
dic/tile.cpp
|
@ -27,6 +27,7 @@
|
|||
#include "header.h"
|
||||
#include "encoding.h"
|
||||
#include "dic_exception.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(dic, Tile);
|
||||
|
@ -149,6 +150,22 @@ unsigned int Tile::toCode() const
|
|||
}
|
||||
|
||||
|
||||
Tile Tile::toLower() const
|
||||
{
|
||||
ASSERT(iswalpha(m_char),
|
||||
"toLower() should be called on alphabetical tiles");
|
||||
return Tile(towlower(m_char));
|
||||
}
|
||||
|
||||
|
||||
Tile Tile::toUpper() const
|
||||
{
|
||||
ASSERT(iswalpha(m_char),
|
||||
"toUpper() should be called on alphabetical tiles");
|
||||
return Tile(towupper(m_char));
|
||||
}
|
||||
|
||||
|
||||
bool Tile::operator<(const Tile &iOther) const
|
||||
{
|
||||
if (m_joker)
|
||||
|
|
|
@ -64,6 +64,11 @@ public:
|
|||
wstring getDisplayStr() const;
|
||||
vector<wstring> getInputStr() const;
|
||||
|
||||
/// Return a copy of this tile, as a (non pure) joker
|
||||
Tile toLower() const;
|
||||
/// Return a copy of this tile, without joker information
|
||||
Tile toUpper() const;
|
||||
|
||||
static const Tile &Joker() { return m_TheJoker; }
|
||||
|
||||
bool operator <(const Tile &iOther) const;
|
||||
|
|
|
@ -417,10 +417,11 @@ void Board::testRound(const Round &iRound)
|
|||
{
|
||||
if (isVacant(row, col + i))
|
||||
{
|
||||
Tile t = iRound.getTile(i);
|
||||
const Tile &t = iRound.getTile(i);
|
||||
if (iRound.isJoker(i))
|
||||
t = Tile(towlower(t.toChar()));
|
||||
m_testsRow[row][col + i] = t;
|
||||
m_testsRow[row][col + i] = t.toLower();
|
||||
else
|
||||
m_testsRow[row][col + i] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -430,10 +431,11 @@ void Board::testRound(const Round &iRound)
|
|||
{
|
||||
if (isVacant(row + i, col))
|
||||
{
|
||||
Tile t = iRound.getTile(i);
|
||||
const Tile &t = iRound.getTile(i);
|
||||
if (iRound.isJoker(i))
|
||||
t = Tile(towlower(t.toChar()));
|
||||
m_testsRow[row + i][col] = t;
|
||||
m_testsRow[row + i][col] = t.toLower();
|
||||
else
|
||||
m_testsRow[row + i][col] = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -352,7 +352,7 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
|
|||
if (bestRound.isJoker(i) && bestRound.isPlayedFromRack(i))
|
||||
{
|
||||
const Tile &jokerTile = bestRound.getTile(i);
|
||||
Tile replacingTile(towupper(jokerTile.toChar()));
|
||||
const Tile &replacingTile = jokerTile.toUpper();
|
||||
LOG_DEBUG("helperSetRackRandom(): replacing Joker with "
|
||||
<< lfw(replacingTile.toChar()));
|
||||
|
||||
|
|
|
@ -113,8 +113,7 @@ void GameMoveCmd::playRound()
|
|||
if (m_round.isPlayedFromRack(i) && m_round.isJoker(i))
|
||||
{
|
||||
// Is the represented letter still available in the bag?
|
||||
// XXX: this way to get the represented letter sucks...
|
||||
Tile t(towupper(m_round.getTile(i).toChar()));
|
||||
const Tile &t = m_round.getTile(i).toUpper();
|
||||
if (bag.in(t))
|
||||
{
|
||||
bag.replaceTile(Tile::Joker());
|
||||
|
|
Loading…
Reference in a new issue