- Removed Game::setRackRandomOld() (replaced by Game::setRackRandom())

- Adapted regression scenarii
This commit is contained in:
Olivier Teulière 2008-01-15 14:56:38 +00:00
parent 6c831c5534
commit 8c3708fa99
10 changed files with 26 additions and 228 deletions

View file

@ -460,158 +460,6 @@ int Game::helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
} }
int Game::helperSetRackRandomOld(unsigned int p, bool iCheck, set_rack_mode mode)
{
ASSERT(p < getNPlayers(), "Wrong player number");
// Make a copy of the current player's rack
PlayedRack pld = getPlayer(p).getCurrentRack();
int nold = pld.getNbOld();
// Create a copy of the bag in which we can do everything we want,
// and take from it the tiles of the players rack so that "bag"
// contains the right number of tiles.
Bag bag(m_dic);
realBag(bag);
if (mode == RACK_NEW && nold != 0)
{
// We may have removed too many letters from the bag (i.e. the 'new'
// letters of the player)
vector<Tile> tiles;
pld.getNewTiles(tiles);
for (unsigned int i = 0; i < tiles.size(); i++)
{
bag.replaceTile(tiles[i]);
}
pld.resetNew();
}
else if (mode == RACK_NEW && nold == 0 || mode == RACK_ALL)
{
// Replace all the tiles in the bag before choosing random ones
vector<Tile> tiles;
pld.getAllTiles(tiles);
for (unsigned int i = 0; i < tiles.size(); i++)
{
bag.replaceTile(tiles[i]);
}
// RACK_NEW with an empty rack is equivalent to RACK_ALL
pld.reset();
// Do not forget to update nold, for the RACK_ALL case
nold = 0;
}
else
{
debug("Game::helperSetRackRandomOld not a random mode\n");
}
// Nothing in the rack, nothing in the bag --> end of the game
if (bag.getNbTiles() == 0 && pld.getNbTiles() == 0)
{
return 1;
}
// When iCheck is true, we must make sure that there are at least 2 vowels
// and 2 consonants in the rack up to the 15th turn, and at least one of
// them from the 16th turn.
// So before trying to fill the rack, we'd better make sure there is a way
// to complete the rack with these constraints...
unsigned int min = 0;
if (iCheck)
{
unsigned int oldc, oldv;
if (bag.getNbVowels() == 0 || bag.getNbConsonants() == 0)
{
return 1;
}
// 2 vowels and 2 consonants are needed up to the 15th turn
if (bag.getNbVowels() > 1 && bag.getNbConsonants() > 1
&& m_history.getSize() < 15)
min = 2;
else
min = 1;
// Count the remaining consonants and vowels in the rack
vector<Tile> tiles;
pld.getOldTiles(tiles);
oldc = 0;
oldv = 0;
for (unsigned int i = 0; i < tiles.size(); i++)
{
if (tiles[i].isConsonant())
oldc++;
if (tiles[i].isVowel())
oldv++;
}
// RACK_SIZE - nold is the number of letters to add
if (min > oldc + RACK_SIZE - nold ||
min > oldv + RACK_SIZE - nold)
{
// We cannot fill the rack with enough vowels or consonants!
return 3;
}
}
// Are we dealing with a normal game or a joker game?
if (m_variant == kJOKER)
{
// 1) Is there already a joker in the remaining letters of the rack?
bool jokerFound = false;
vector<Tile> tiles;
pld.getOldTiles(tiles);
for (unsigned int i = 0; i < tiles.size(); i++)
{
if (tiles[i].isJoker())
{
jokerFound = true;
break;
}
}
// 2) If there was no joker, we add one if possible
if (!jokerFound && bag.in(Tile::Joker()))
{
bag.takeTile(Tile::Joker());
pld.addNew(Tile::Joker());
}
// 3) Complete the rack normally... but without any joker!
Tile l;
// FIXME: this can be an infinite loop if the only tile left in the
// bag is a joker!
while (bag.getNbTiles() != 0 && pld.getNbTiles() != RACK_SIZE)
{
l = bag.selectRandom();
if (!l.isJoker())
{
bag.takeTile(l);
pld.addNew(l);
}
}
}
else // Normal game
{
// Get new tiles from the bag
Tile l;
while (bag.getNbTiles() != 0 && pld.getNbTiles() != RACK_SIZE)
{
l = bag.selectRandom();
bag.takeTile(l);
pld.addNew(l);
}
}
if (iCheck && !pld.checkRack(min, min))
return 2;
m_players[p]->setCurrentRack(pld);
return 0;
}
bool Game::rackInBag(const Rack &iRack, const Bag &iBag) const bool Game::rackInBag(const Rack &iRack, const Bag &iBag) const
{ {
const vector<Tile>& allTiles = m_dic.getAllTiles(); const vector<Tile>& allTiles = m_dic.getAllTiles();

View file

@ -257,20 +257,6 @@ protected:
*/ */
int helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode); int helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode);
/**
* Set the rack randomly for the player p
* Possible return values:
* 0: everything went fine
* 1: the game is over
* 2: the rack was checked and was not correct (try calling the
* function again)
* 3: there is no chance to set the rack with the vowels/consonants
* constraints
*
* @deprecated: use helperSetRackRandom instead
*/
int helperSetRackRandomOld(unsigned int p, bool iCheck, set_rack_mode mode);
/** /**
* Set the rack for the player p with the given letters * Set the rack for the player p with the given letters
* Possible return values: * Possible return values:

View file

@ -42,20 +42,8 @@ Training::Training(const Dictionary &iDic)
int Training::setRackRandom(bool iCheck, set_rack_mode mode) int Training::setRackRandom(bool iCheck, set_rack_mode mode)
{ {
#define MAX_RANDOM_TRY 5
int res;
int try_number = 0;
m_results.clear(); m_results.clear();
do return helperSetRackRandom(m_currPlayer, iCheck, mode);
{
res = helperSetRackRandomOld(m_currPlayer, iCheck, mode);
try_number ++;
} while (res == 2 && try_number < MAX_RANDOM_TRY);
// 0 : ok
// 1 : not enough tiles
// 2 : check failed (number of voyels before round 15)
return res;
} }

View file

@ -27,9 +27,9 @@ training_racc 0 # randseed unused
# Test the 7 + 1 feature # Test the 7 + 1 feature
training_7pl1 0 # randseed unused training_7pl1 0 # randseed unused
# Several ways of getting a rack and playing a word # Several ways of getting a rack and playing a word
training_play 4 training_play 0 # randseed unused
# Training rack+search+play+back # Training rack+search+play+back
training_back 5 training_back 0 # randseed unused
# Joker problem on game search # Joker problem on game search
training_rosace 0 training_rosace 0
@ -74,7 +74,7 @@ freegame_3_ai 2
# load a standard training game (fumee) # load a standard training game (fumee)
load_game 0 load_game 0
# save and reload a training game, standard format # save and reload a training game, standard format
load_saved_game 5 load_saved_game 0 # randseed unused
# load a training game with advanced format (test.elt) # load a training game with advanced format (test.elt)
# load_test_adv 0 # We need to specifie a much more complete file format # load_test_adv 0 # We need to specifie a much more complete file format
# before we can handle load/save on duplicate and # before we can handle load/save on duplicate and

View file

@ -1,10 +1,8 @@
e e
* t EA?AEBF
a t
r r
n 1 n 1
+ t LMUAEYE
a t
r r
a r a r
n 2 n 2
@ -15,15 +13,13 @@ n -1
r r
n 1 n 1
+ t EELMUJE
a t
r r
a r a r
n 1 n 1
a g a g
+ t EEIGLEH
a t
r r
a r a r
n 3 n 3

View file

@ -2,14 +2,10 @@
commande> e commande> e
mode entraînement mode entraînement
[?] pour l'aide [?] pour l'aide
commande> * commande> t EA?AEBF
commande> a t
EA?AEBF
commande> r commande> r
commande> n 1 commande> n 1
commande> + commande> t LMUAEYE
commande> a t
LMUAEYE
commande> r commande> r
commande> a r commande> a r
1: AY 46 I6 1: AY 46 I6
@ -46,9 +42,7 @@ commande>
commande> r commande> r
commande> n 1 commande> n 1
commande> commande>
commande> + commande> t EELMUJE
commande> a t
EELMUJE
commande> r commande> r
commande> a r commande> a r
1: JUMEL 38 J2 1: JUMEL 38 J2
@ -80,9 +74,7 @@ commande> a g
N - - - - - - - - - - - - - - - N - - - - - - - - - - - - - - -
O - - - - - - - - - - - - - - - O - - - - - - - - - - - - - - -
commande> commande>
commande> + commande> t EEIGLEH
commande> a t
EEIGLEH
commande> r commande> r
commande> a r commande> a r
1: HELIEE 34 K5 1: HELIEE 34 K5
@ -124,8 +116,8 @@ Player 0: Human
===|==========|=================|=====|=====|===|====== ===|==========|=================|=====|=====|===|======
1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | * 1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | *
2 | LMUAEYE | AY | I6 | 46 | 0 | 2 | LMUAEYE | AY | I6 | 46 | 0 |
3 | EELMU+JE | JUMEL | J2 | 38 | 0 | 3 | EELMUJE | JUMEL | J2 | 38 | 0 |
4 | EE+IGLEH | EGAYEE | 7F | 32 | 0 | 4 | EEIGLEH | EGAYEE | 7F | 32 | 0 |
Total: 196 Total: 196
@ -168,8 +160,8 @@ Player 0: Human
===|==========|=================|=====|=====|===|====== ===|==========|=================|=====|=====|===|======
1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | * 1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | *
2 | LMUAEYE | AY | I6 | 46 | 0 | 2 | LMUAEYE | AY | I6 | 46 | 0 |
3 | EELMU+JE | JUMEL | J2 | 38 | 0 | 3 | EELMUJE | JUMEL | J2 | 38 | 0 |
4 | EE+IGLEH | EGAYEE | 7F | 32 | 0 | 4 | EEIGLEH | EGAYEE | 7F | 32 | 0 |
Total: 196 Total: 196

View file

@ -1,10 +1,8 @@
e e
* t EA?AEBF
a t
r r
n 1 n 1
+ t LMUAEYE
a t
r r
a r a r
n 2 n 2
@ -21,7 +19,7 @@ a g
a l a l
n -1 n -1
a s a s
* t IEIEIEF
r r
n 1 n 1
a s a s

View file

@ -2,14 +2,10 @@
commande> e commande> e
mode entraînement mode entraînement
[?] pour l'aide [?] pour l'aide
commande> * commande> t EA?AEBF
commande> a t
EA?AEBF
commande> r commande> r
commande> n 1 commande> n 1
commande> + commande> t LMUAEYE
commande> a t
LMUAEYE
commande> r commande> r
commande> a r commande> a r
1: AY 46 I6 1: AY 46 I6
@ -113,7 +109,7 @@ commande> a l
commande> n -1 commande> n -1
commande> a s commande> a s
0 0
commande> * commande> t IEIEIEF
commande> r commande> r
commande> n 1 commande> n 1
commande> a s commande> a s

View file

@ -1,6 +1,5 @@
e e
* t IEJDEUE
a t
j INVALID XX j INVALID XX
j INVALID H5 j INVALID H5
j MAUVAIS H5 j MAUVAIS H5
@ -10,8 +9,7 @@ r
n 0 n 0
n 6 n 6
a t a t
+ t DEEIPEG
a t
j PIEGEE H4 j PIEGEE H4
j PIEGEE A1 j PIEGEE A1
j PIEGEE 7C j PIEGEE 7C

View file

@ -2,9 +2,7 @@
commande> e commande> e
mode entraînement mode entraînement
[?] pour l'aide [?] pour l'aide
commande> * commande> t IEJDEUE
commande> a t
UDEEEIJ
commande> j INVALID XX commande> j INVALID XX
Mot incorrect ou mal placé (2) Mot incorrect ou mal placé (2)
commande> j INVALID H5 commande> j INVALID H5
@ -20,9 +18,7 @@ commande> n 0
commande> n 6 commande> n 6
commande> a t commande> a t
DEEI DEEI
commande> + commande> t DEEIPEG
commande> a t
DEEIPEG
commande> j PIEGEE H4 commande> j PIEGEE H4
Mot incorrect ou mal placé (6) Mot incorrect ou mal placé (6)
commande> j PIEGEE A1 commande> j PIEGEE A1