From 7e7f7f2dfa324076d7a897b401f58710b657a127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Thu, 10 Jan 2008 10:23:36 +0000 Subject: [PATCH] - 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 --- game/game.cpp | 43 +++++++++++++++++++++-------------------- test/duplicate_2_ai.ref | 23 +++++++++++----------- wxwin/mainframe.cc | 36 +++++++++++++++++----------------- 3 files changed, 52 insertions(+), 50 deletions(-) diff --git a/game/game.cpp b/game/game.cpp index 3990d3d..8a8d8b2 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -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 if (bag.getNbTiles() == 0 && pld.getNbTiles() == 0) { 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 if (iCheck) { - if (bag.getNbVowels() == 0 || bag.getNbConsonants() == 0 || - bag.getNbTiles() == 1) + if (bag.getNbVowels() < neededVowels || + bag.getNbConsonants() < neededConsonants || + (bag.getNbTiles() + tiles.size()) == 1) { return 1; } @@ -383,25 +403,6 @@ int Game::helperSetRackRandom(unsigned int p, bool iCheck, set_rack_mode mode) if (jokerAdded) 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 if (neededVowels > RACK_SIZE - tiles.size() || neededConsonants > RACK_SIZE - tiles.size()) diff --git a/test/duplicate_2_ai.ref b/test/duplicate_2_ai.ref index 260f324..690d13a 100644 --- a/test/duplicate_2_ai.ref +++ b/test/duplicate_2_ai.ref @@ -3,14 +3,14 @@ commande> d 0 2 mode duplicate [?] pour l'aide commande> a S -Joueur 0: 918 -Joueur 1: 918 +Joueur 0: 931 +Joueur 1: 931 commande> a T -Joueur 0: DQRU -Joueur 1: DQRU +Joueur 0: R +Joueur 1: R 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 ? - 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 Eliot 1.5 @@ -42,11 +42,12 @@ Player 1: Computer 20 | TOEHLRT | PHOT | 8L | 27 | 0 | 21 | ELRT+NME | REMELENT | C2 | 70 | 0 | * 22 | QDRMUTI | MITAN | 5E | 20 | 0 | + 23 | DQRU | QUID | 13H | 13 | 0 | - Total: 918 + Total: 931 -Rack 0: DQRU -Rack 1: DQRU +Rack 0: R +Rack 1: R commande> a g 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 A - - - - - - - - - - - H A V A @@ -56,10 +57,10 @@ commande> a g E - - - - M - R - L - E - - - - F - - - - I C I - O K A - - - - G - - - - T U S - P I N - - - - - H - - - F A B A c E E S - - - - - I - - V I N E S - - F - - - - - + H - - - F A B A c E E S - Q - - + I - - V I N E S - - F - - U - - 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 M U - - - - - - H - - - - - - L N M O L L I T - O - C A R G U E diff --git a/wxwin/mainframe.cc b/wxwin/mainframe.cc index 09a066f..94e20b9 100644 --- a/wxwin/mainframe.cc +++ b/wxwin/mainframe.cc @@ -178,24 +178,6 @@ MainFrame::MainFrame(wxPoint __UNUSED__ pos_, wxSize size_) listsizer->Add(reslist, 1, wxEXPAND | wxLEFT | wxRIGHT, 1); #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(); statusbar = CreateStatusBar(2, 0, Status_ID); @@ -239,6 +221,24 @@ MainFrame::MainFrame(wxPoint __UNUSED__ pos_, wxSize size_) SetClientSize(size_); 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(); }