void DebugEnabler::debugCopy(const DebugEnabler* original) { if (original) { m_level = original->debugLevel(); m_enabled = original->debugEnabled(); } else { m_level = TelEngine::debugLevel(); m_enabled = debugEnabled(); } m_chain = 0; }
/** *@return the best position for the letter */ int Hangman::bestPosition(){ vector<int> positions (hangManWord.length(),0); int notIn =0; //go through words list for(long i=0; i<equiv.size();i++){ //bump count notIn if letter isnt in the word bool contains = false; if(equiv[i].find(guessedLetter) == string::npos){ notIn++; contains = true; } if(!contains){ //go through word[i] of wordlist for(int k=0;k<hangManWord.length();k++){ if(equiv[i].at(k)==guessedLetter){ positions[k]++; } } } } //which is the best position //to do this we need to know which will leave us with most words int biggestPosition = positions[0]; int bestPosition =0; for(int i=1;i<hangManWord.length();i++){ if(positions[i]>biggestPosition){ bestPosition = i; biggestPosition = positions[i]; } } if(notIn>biggestPosition){ bestPosition =-1; } //if in debug mode print out the positions families if(debugEnabled()){ cout << "Letter not in word: " << notIn <<endl; for(int i=0; i<hangManWord.length();i++){ cout << positions[i] << " "; } cout << "best position: " <<bestPosition <<endl; } return bestPosition; }
inline StreamLogger debug() { return debugEnabled() ? StreamLogger([](const std::string& msg) { logger().debug(msg); }, "DBG") : StreamLogger(); }