mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-12-27 09:58:08 +01:00
- Removed Game::setRackRandomOld() (replaced by Game::setRackRandom())
- Adapted regression scenarii
This commit is contained in:
parent
6c831c5534
commit
8c3708fa99
10 changed files with 26 additions and 228 deletions
152
game/game.cpp
152
game/game.cpp
|
@ -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
|
||||
{
|
||||
const vector<Tile>& allTiles = m_dic.getAllTiles();
|
||||
|
|
14
game/game.h
14
game/game.h
|
@ -257,20 +257,6 @@ protected:
|
|||
*/
|
||||
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
|
||||
* Possible return values:
|
||||
|
|
|
@ -42,20 +42,8 @@ Training::Training(const Dictionary &iDic)
|
|||
|
||||
int Training::setRackRandom(bool iCheck, set_rack_mode mode)
|
||||
{
|
||||
#define MAX_RANDOM_TRY 5
|
||||
|
||||
int res;
|
||||
int try_number = 0;
|
||||
m_results.clear();
|
||||
do
|
||||
{
|
||||
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;
|
||||
return helperSetRackRandom(m_currPlayer, iCheck, mode);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -27,9 +27,9 @@ training_racc 0 # randseed unused
|
|||
# Test the 7 + 1 feature
|
||||
training_7pl1 0 # randseed unused
|
||||
# Several ways of getting a rack and playing a word
|
||||
training_play 4
|
||||
training_play 0 # randseed unused
|
||||
# Training rack+search+play+back
|
||||
training_back 5
|
||||
training_back 0 # randseed unused
|
||||
# Joker problem on game search
|
||||
training_rosace 0
|
||||
|
||||
|
@ -74,7 +74,7 @@ freegame_3_ai 2
|
|||
# load a standard training game (fumee)
|
||||
load_game 0
|
||||
# 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_test_adv 0 # We need to specifie a much more complete file format
|
||||
# before we can handle load/save on duplicate and
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
e
|
||||
*
|
||||
a t
|
||||
t EA?AEBF
|
||||
r
|
||||
n 1
|
||||
+
|
||||
a t
|
||||
t LMUAEYE
|
||||
r
|
||||
a r
|
||||
n 2
|
||||
|
@ -15,15 +13,13 @@ n -1
|
|||
r
|
||||
n 1
|
||||
|
||||
+
|
||||
a t
|
||||
t EELMUJE
|
||||
r
|
||||
a r
|
||||
n 1
|
||||
a g
|
||||
|
||||
+
|
||||
a t
|
||||
t EEIGLEH
|
||||
r
|
||||
a r
|
||||
n 3
|
||||
|
|
|
@ -2,14 +2,10 @@
|
|||
commande> e
|
||||
mode entraînement
|
||||
[?] pour l'aide
|
||||
commande> *
|
||||
commande> a t
|
||||
EA?AEBF
|
||||
commande> t EA?AEBF
|
||||
commande> r
|
||||
commande> n 1
|
||||
commande> +
|
||||
commande> a t
|
||||
LMUAEYE
|
||||
commande> t LMUAEYE
|
||||
commande> r
|
||||
commande> a r
|
||||
1: AY 46 I6
|
||||
|
@ -46,9 +42,7 @@ commande>
|
|||
commande> r
|
||||
commande> n 1
|
||||
commande>
|
||||
commande> +
|
||||
commande> a t
|
||||
EELMUJE
|
||||
commande> t EELMUJE
|
||||
commande> r
|
||||
commande> a r
|
||||
1: JUMEL 38 J2
|
||||
|
@ -80,9 +74,7 @@ commande> a g
|
|||
N - - - - - - - - - - - - - - -
|
||||
O - - - - - - - - - - - - - - -
|
||||
commande>
|
||||
commande> +
|
||||
commande> a t
|
||||
EEIGLEH
|
||||
commande> t EEIGLEH
|
||||
commande> r
|
||||
commande> a r
|
||||
1: HELIEE 34 K5
|
||||
|
@ -124,8 +116,8 @@ Player 0: Human
|
|||
===|==========|=================|=====|=====|===|======
|
||||
1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | *
|
||||
2 | LMUAEYE | AY | I6 | 46 | 0 |
|
||||
3 | EELMU+JE | JUMEL | J2 | 38 | 0 |
|
||||
4 | EE+IGLEH | EGAYEE | 7F | 32 | 0 |
|
||||
3 | EELMUJE | JUMEL | J2 | 38 | 0 |
|
||||
4 | EEIGLEH | EGAYEE | 7F | 32 | 0 |
|
||||
|
||||
Total: 196
|
||||
|
||||
|
@ -168,8 +160,8 @@ Player 0: Human
|
|||
===|==========|=================|=====|=====|===|======
|
||||
1 | EA?AEBF | FABAcEE | H4 | 80 | 0 | *
|
||||
2 | LMUAEYE | AY | I6 | 46 | 0 |
|
||||
3 | EELMU+JE | JUMEL | J2 | 38 | 0 |
|
||||
4 | EE+IGLEH | EGAYEE | 7F | 32 | 0 |
|
||||
3 | EELMUJE | JUMEL | J2 | 38 | 0 |
|
||||
4 | EEIGLEH | EGAYEE | 7F | 32 | 0 |
|
||||
|
||||
Total: 196
|
||||
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
e
|
||||
*
|
||||
a t
|
||||
t EA?AEBF
|
||||
r
|
||||
n 1
|
||||
+
|
||||
a t
|
||||
t LMUAEYE
|
||||
r
|
||||
a r
|
||||
n 2
|
||||
|
@ -21,7 +19,7 @@ a g
|
|||
a l
|
||||
n -1
|
||||
a s
|
||||
*
|
||||
t IEIEIEF
|
||||
r
|
||||
n 1
|
||||
a s
|
||||
|
|
|
@ -2,14 +2,10 @@
|
|||
commande> e
|
||||
mode entraînement
|
||||
[?] pour l'aide
|
||||
commande> *
|
||||
commande> a t
|
||||
EA?AEBF
|
||||
commande> t EA?AEBF
|
||||
commande> r
|
||||
commande> n 1
|
||||
commande> +
|
||||
commande> a t
|
||||
LMUAEYE
|
||||
commande> t LMUAEYE
|
||||
commande> r
|
||||
commande> a r
|
||||
1: AY 46 I6
|
||||
|
@ -113,7 +109,7 @@ commande> a l
|
|||
commande> n -1
|
||||
commande> a s
|
||||
0
|
||||
commande> *
|
||||
commande> t IEIEIEF
|
||||
commande> r
|
||||
commande> n 1
|
||||
commande> a s
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
e
|
||||
*
|
||||
a t
|
||||
t IEJDEUE
|
||||
j INVALID XX
|
||||
j INVALID H5
|
||||
j MAUVAIS H5
|
||||
|
@ -10,8 +9,7 @@ r
|
|||
n 0
|
||||
n 6
|
||||
a t
|
||||
+
|
||||
a t
|
||||
t DEEIPEG
|
||||
j PIEGEE H4
|
||||
j PIEGEE A1
|
||||
j PIEGEE 7C
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
commande> e
|
||||
mode entraînement
|
||||
[?] pour l'aide
|
||||
commande> *
|
||||
commande> a t
|
||||
UDEEEIJ
|
||||
commande> t IEJDEUE
|
||||
commande> j INVALID XX
|
||||
Mot incorrect ou mal placé (2)
|
||||
commande> j INVALID H5
|
||||
|
@ -20,9 +18,7 @@ commande> n 0
|
|||
commande> n 6
|
||||
commande> a t
|
||||
DEEI
|
||||
commande> +
|
||||
commande> a t
|
||||
DEEIPEG
|
||||
commande> t DEEIPEG
|
||||
commande> j PIEGEE H4
|
||||
Mot incorrect ou mal placé (6)
|
||||
commande> j PIEGEE A1
|
||||
|
|
Loading…
Reference in a new issue