- wxwin/mainframe.cc: Fixed a crash occurring when no config file is found

- Fixed a bug occurring in duplicate mode: sometimes the game ended too early,
   while it was still allowed to go on.
   Also updated the corresponding regression scenario
This commit is contained in:
Olivier Teulière 2008-01-10 10:23:36 +00:00
parent 81e980104f
commit 7e7f7f2dfa
3 changed files with 52 additions and 50 deletions

View file

@ -336,16 +336,36 @@ int Game::helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
} }
} }
// Count the needed consonants and vowels in the rack
// (i.e. minimum required, minus what we already have in the rack)
unsigned int neededVowels = min;
unsigned int neededConsonants = min;
for (unsigned int i = 0; i < tiles.size(); ++i)
{
if (neededVowels > 0 && tiles[i].isVowel())
neededVowels--;
if (neededConsonants > 0 && tiles[i].isConsonant())
neededConsonants--;
}
// Nothing in the rack, nothing in the bag --> end of the (free)game // Nothing in the rack, nothing in the bag --> end of the (free)game
if (bag.getNbTiles() == 0 && pld.getNbTiles() == 0) if (bag.getNbTiles() == 0 && pld.getNbTiles() == 0)
{ {
return 1; return 1;
} }
// Check whether it is possible to complete the rack properly
if (bag.getNbVowels() < neededVowels ||
bag.getNbConsonants() < neededConsonants)
{
return 1;
}
// End of game condition // End of game condition
if (iCheck) if (iCheck)
{ {
if (bag.getNbVowels() == 0 || bag.getNbConsonants() == 0 || if (bag.getNbVowels() < neededVowels ||
bag.getNbTiles() == 1) bag.getNbConsonants() < neededConsonants ||
(bag.getNbTiles() + tiles.size()) == 1)
{ {
return 1; return 1;
} }
@ -383,25 +403,6 @@ int Game::helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode)
if (jokerAdded) if (jokerAdded)
pld.addNew(Tile::Joker()); pld.addNew(Tile::Joker());
// Count the needed consonants and vowels in the rack
// (i.e. minimum required, minus what we already have in the rack)
unsigned int neededVowels = min;
unsigned int neededConsonants = min;
for (unsigned int i = 0; i < tiles.size(); ++i)
{
if (neededVowels > 0 && tiles[i].isVowel())
neededVowels--;
if (neededConsonants > 0 && tiles[i].isConsonant())
neededConsonants--;
}
// Check whether it is possible to complete the rack properly
if (bag.getNbVowels() < neededVowels ||
bag.getNbConsonants() < neededConsonants)
{
return 1;
}
// RACK_SIZE - tiles.size() is the number of letters to add to the rack // RACK_SIZE - tiles.size() is the number of letters to add to the rack
if (neededVowels > RACK_SIZE - tiles.size() || if (neededVowels > RACK_SIZE - tiles.size() ||
neededConsonants > RACK_SIZE - tiles.size()) neededConsonants > RACK_SIZE - tiles.size())

View file

@ -3,14 +3,14 @@ commande> d 0 2
mode duplicate mode duplicate
[?] pour l'aide [?] pour l'aide
commande> a S commande> a S
Joueur 0: 918 Joueur 0: 931
Joueur 1: 918 Joueur 1: 931
commande> a T commande> a T
Joueur 0: DQRU Joueur 0: R
Joueur 1: DQRU Joueur 1: R
commande> a l commande> a l
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ? A B C D E F G H I J K L M N O P Q R S T U V W X Y Z ?
0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
commande> a p commande> a p
Eliot 1.5 Eliot 1.5
@ -42,11 +42,12 @@ Player 1: Computer
20 | TOEHLRT | PHOT | 8L | 27 | 0 | 20 | TOEHLRT | PHOT | 8L | 27 | 0 |
21 | ELRT+NME | REMELENT | C2 | 70 | 0 | * 21 | ELRT+NME | REMELENT | C2 | 70 | 0 | *
22 | QDRMUTI | MITAN | 5E | 20 | 0 | 22 | QDRMUTI | MITAN | 5E | 20 | 0 |
23 | DQRU | QUID | 13H | 13 | 0 |
Total: 918 Total: 931
Rack 0: DQRU Rack 0: R
Rack 1: DQRU Rack 1: R
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 - - - - - - - - - - - H A V A A - - - - - - - - - - - H A V A
@ -56,10 +57,10 @@ commande> a g
E - - - - M - R - L - E - - - - E - - - - M - R - L - E - - - -
F - - - - I C I - O K A - - - - F - - - - I C I - O K A - - - -
G - - - - T U S - P I N - - - - G - - - - T U S - P I N - - - -
H - - - F A B A c E E S - - - - H - - - F A B A c E E S - Q - -
I - - V I N E S - - F - - - - - I - - V I N E S - - F - - U - -
J - W A X - B - - - S E R I N S J - W A X - B - - - S E R I N S
K D U N E - E - - - - - - - - T K D U N E - E - - - - - - D - T
L O - - E - S E P T I m E - - Y L O - - E - S E P T I m E - - Y
M U - - - - - - H - - - - - - L M U - - - - - - H - - - - - - L
N M O L L I T - O - C A R G U E N M O L L I T - O - C A R G U E

View file

@ -178,24 +178,6 @@ MainFrame::MainFrame(wxPoint __UNUSED__ pos_, wxSize size_)
listsizer->Add(reslist, 1, wxEXPAND | wxLEFT | wxRIGHT, 1); listsizer->Add(reslist, 1, wxEXPAND | wxLEFT | wxRIGHT, 1);
#endif #endif
wxString dicpath = config.getDicPath();
try
{
Dictionary *dic = new Dictionary(dicpath.mb_str().data());
m_dic = dic;
m_game = GameFactory::Instance()->createTraining(*m_dic);
if (m_game)
{
m_game->start();
}
}
catch (std::exception &e)
{
wxCommandEvent event;
// This will also start a new training game indirectly
OnMenuConfGameDic(event);
}
InitMenu(); InitMenu();
statusbar = CreateStatusBar(2, 0, Status_ID); statusbar = CreateStatusBar(2, 0, Status_ID);
@ -239,6 +221,24 @@ MainFrame::MainFrame(wxPoint __UNUSED__ pos_, wxSize size_)
SetClientSize(size_); SetClientSize(size_);
Move(config.getFramePos(wxT(APPNAME))); Move(config.getFramePos(wxT(APPNAME)));
wxString dicpath = config.getDicPath();
try
{
Dictionary *dic = new Dictionary(dicpath.mb_str().data());
m_dic = dic;
m_game = GameFactory::Instance()->createTraining(*m_dic);
if (m_game)
{
m_game->start();
}
}
catch (std::exception &e)
{
wxCommandEvent event;
// This will also start a new training game indirectly
OnMenuConfGameDic(event);
}
InitFrames(); InitFrames();
} }