From e8225ad9afcaec99d740b376d9c61c1c84b06569 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Thu, 5 Sep 2024 21:35:48 +0200 Subject: [PATCH] Simplify a bit --- src/evilhangman.cpp | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/src/evilhangman.cpp b/src/evilhangman.cpp index b584f1b..273ea27 100755 --- a/src/evilhangman.cpp +++ b/src/evilhangman.cpp @@ -157,7 +157,6 @@ int main(int argc, char *argv[]) { std::vector guessedChars; size_t wrongAttempts = 0; bool hasWon = false, hasLost = false; - std::string currentlyThinkingOf(wordLength, '-'); do { char guess; @@ -183,15 +182,14 @@ int main(int argc, char *argv[]) { families.begin(), families.end(), [](const Entry &a, const Entry &b) { return a.second.size() < b.second.size(); }); - currentlyThinkingOf = biggestEntry->first; + guessProgress = biggestEntry->first; dictionary = biggestEntry->second; - }else{ + } else { std::string &word = dictionary[0]; - for (size_t i = 0; i < word.size(); i++) { if (word[i] != guess) continue; - currentlyThinkingOf[i] = guess; + guessProgress[i] = guess; } } @@ -200,14 +198,7 @@ int main(int argc, char *argv[]) { printContainer(dictionary, ", "); } - bool wasCorrect = false; - for (size_t i = 0; i < currentlyThinkingOf.size(); ++i) { - if (currentlyThinkingOf[i] == guess) { - guessProgress[i] = guess; - wasCorrect = true; - } - } - + bool wasCorrect = guessProgress.find(guess) != std::string::npos; if (wasCorrect) { std::cout << "Correct!" << std::endl; } else { @@ -219,7 +210,7 @@ int main(int argc, char *argv[]) { std::cout << "Used letters: "; printContainer(guessedChars, " "); - std::cout << "Word: " << currentlyThinkingOf << std::endl; + std::cout << "Word: " << guessProgress << std::endl; // Check if all the characters in the final word have been guessed hasWon = std::all_of(guessProgress.begin(), guessProgress.end(),