Fix a small bug in explosive games.

Before this commit, if the top move did not need the blank tile, the
blank tile stayed in the rack. It is now replaced with another (randomly
selected) tile.
This commit is contained in:
Olivier Teulière 2013-01-16 18:04:57 +01:00
parent 83baec368b
commit 4e533eed27
2 changed files with 61 additions and 49 deletions

View file

@ -463,37 +463,47 @@ PlayedRack Game::helperSetRackRandom(const PlayedRack &iPld,
<< lfw(pld.toString()) << " (best word: " << lfw(pld.toString()) << " (best word: "
<< lfw(bestRound.getWord()) << ")"); << lfw(bestRound.getWord()) << ")");
// Identify the joker // Identify the tile we should use to replace the joker
Tile replacingTile;
bool jokerUsed = false;
for (unsigned int i = 0; i < bestRound.getWordLen(); ++i) for (unsigned int i = 0; i < bestRound.getWordLen(); ++i)
{ {
if (bestRound.isJoker(i) && bestRound.isPlayedFromRack(i)) if (bestRound.isJoker(i) && bestRound.isPlayedFromRack(i))
{ {
const Tile &jokerTile = bestRound.getTile(i); const Tile &jokerTile = bestRound.getTile(i);
const Tile &replacingTile = jokerTile.toUpper(); replacingTile = jokerTile.toUpper();
LOG_DEBUG("helperSetRackRandom(): replacing Joker with " jokerUsed = true;
<< lfw(replacingTile.toChar()));
// If the bag does not contain this letter anymore,
// simply keep the joker in the rack.
if (bag.in(replacingTile))
{
// The bag contains the replacing letter
// We need to swap the joker (it is necessarily in the
// new tiles, because jokerAdded is true)
Rack tmpRack = pld.getNew();
ASSERT(tmpRack.in(Tile::Joker()),
"No joker found in the new tiles!");
tmpRack.remove(Tile::Joker());
tmpRack.add(replacingTile);
pld.setNew(tmpRack);
// Make sure the invariant is still correct, otherwise we keep the joker
if (!pld.checkRack(min, min))
pld = pldCopy;
}
break; break;
} }
} }
if (!jokerUsed)
{
// The joker was not needed for the top. Replace it with a
// randomly selected tile
LOG_DEBUG("helperSetRackRandom(): joker not needed for the top");
replacingTile = bag.selectRandom();
}
LOG_DEBUG("helperSetRackRandom(): replacing Joker with "
<< lfw(replacingTile.toChar()));
// If the bag does not contain the letter anymore,
// simply keep the joker in the rack.
if (bag.in(replacingTile))
{
// The bag contains the replacing letter
// We need to swap the joker (it is necessarily in the
// new tiles, because jokerAdded is true)
Rack tmpRack = pld.getNew();
ASSERT(tmpRack.in(Tile::Joker()), "No joker found in the new tiles");
tmpRack.remove(Tile::Joker());
tmpRack.add(replacingTile);
pld.setNew(tmpRack);
// Make sure the invariant is still correct, otherwise we keep the joker
if (!pld.checkRack(min, min))
pld = pldCopy;
}
} }
} }

View file

@ -5,21 +5,21 @@ mode duplicate
[?] pour l'aide [?] pour l'aide
commande> a g commande> a g
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
A - - - - - - - - - M - - - - - A - - - V E R O N A I S E - - -
B - K - - - J - - - O - N - - - B - K - - - - - - - N - N - - -
C - W E B R A D I O S - O - - - C - W E B R A D I O S - O - - -
D F A - O - U - - - - - T - - - D F A - O - - - - - O - L - - -
E E S - G E N I C U L E e - - - E E S - G E N I C U L E s - - -
F R - - H - E - - - - - R - - - F R - - H - - - - - A - - - - -
G I - - E - - - - - - - A - - - G I - - E - - J - - N - - - - -
H A G L Y P H E S - L A I N E E H A G L Y P H E S - T - - - - -
I - - - S U A - P L a N T O N S I - - - s - - - P - - - L - - -
J - - - - - - - E - - - - - - - J - - - - M E - E - Q - U - - -
K - - - - A T T E N U E Z - - - K - - - - A T T E N U E Z - - M
L - - - C - - - D - - - O - - - L - - - C - - - D - E - U - - O
M - T R E V I R A T - - I - - - M - T R E V I R A T - - L - - I
N - - - U - - - I - V I D E R - N - - - U - - - I - - D E B A T
O F A U X - - - S - - - E - - - O F A U X - - - S - - - S - - I
commande> a p commande> a p
Game: player 1 out of 1 Game: player 1 out of 1
Game: mode=Duplicate Game: mode=Duplicate
@ -36,20 +36,22 @@ Game: history:
7 | A+ZTTNUE | ATTENUEZ | K5 | 118 | * 7 | A+ZTTNUE | ATTENUEZ | K5 | 118 | *
8 | CEUIELN | GENICULE | E4 | 94 | * 8 | CEUIELN | GENICULE | E4 | 94 | *
9 | TVIRETR | TREVIRAT | M2 | 76 | * 9 | TVIRETR | TREVIRAT | M2 | 76 | *
10 | CSN?UXN | CEUX | 4L | 50 | 10 | UXSNNCA | CEUX | 4L | 50 |
11 | NNS?+LOT | PLaNTONS | I8 | 61 | * 11 | ANNS+IOT | INSOLANT | 10A | 83 | *
12 | ?OUANAF | FAUX | O1 | 48 | 12 | UAVNFOA | FAUX | O1 | 48 |
13 | ANO?+RTI | NOTeRAIT | 12B | 77 | * 13 | ANOV+RSE | VERONAIS | A4 | 95 | *
14 | MLIEDNO | ZOIDE | 12K | 32 | 14 | ESULOUL | LUZULES | 12I | 34 |
15 | LMN+AUSE | SUA | I4 | 34 | 15 | O+LMEM?N | ENOLs | 12A | 34 |
16 | ELMN+ARE | LAINEE | H10 | 31 | 16 | MM+QBTDE | QUE | 10J | 26 |
17 | MR+IVMEL | VIDER | N10 | 34 | 17 | BDMMT+M? | BOGHEYs | 4C | 21 |
18 | LMM+QUEJ | JAUNE | 6B | 30 | 18 | BDMMMT+A | DEBAT | N11 | 16 |
19 | LMMQ+OSM | MOS | 10A | 27 | 19 | MMM+JIRI | JE | 7G | 17 |
20 | IIMMMR+O | MOITI | 15K | 21 |
21 | MMR+E | ME | J5 | 12 |
Rack 0: LMMQ Rack 0: MR
Score 0: 1159 Score 0: 1192
commande> q commande> q
fin du mode duplicate fin du mode duplicate
commande> q commande> q