Simplify a bit

This commit is contained in:
Love 2024-09-05 21:35:48 +02:00
parent 4d124ef849
commit dcb10a1eb7

View File

@ -157,7 +157,6 @@ int main(int argc, char *argv[]) {
std::vector<char> guessedChars; std::vector<char> guessedChars;
size_t wrongAttempts = 0; size_t wrongAttempts = 0;
bool hasWon = false, hasLost = false; bool hasWon = false, hasLost = false;
std::string currentlyThinkingOf(wordLength, '-');
do { do {
char guess; char guess;
@ -183,15 +182,14 @@ int main(int argc, char *argv[]) {
families.begin(), families.end(), [](const Entry &a, const Entry &b) { families.begin(), families.end(), [](const Entry &a, const Entry &b) {
return a.second.size() < b.second.size(); return a.second.size() < b.second.size();
}); });
currentlyThinkingOf = biggestEntry->first; guessProgress = biggestEntry->first;
dictionary = biggestEntry->second; dictionary = biggestEntry->second;
} else { } else {
std::string &word = dictionary[0]; std::string &word = dictionary[0];
for (size_t i = 0; i < word.size(); i++) { for (size_t i = 0; i < word.size(); i++) {
if (word[i] != guess) if (word[i] != guess)
continue; continue;
currentlyThinkingOf[i] = guess; guessProgress[i] = guess;
} }
} }
@ -200,14 +198,7 @@ int main(int argc, char *argv[]) {
printContainer(dictionary, ", "); printContainer(dictionary, ", ");
} }
bool wasCorrect = false; bool wasCorrect = guessProgress.find(guess) != std::string::npos;
for (size_t i = 0; i < currentlyThinkingOf.size(); ++i) {
if (currentlyThinkingOf[i] == guess) {
guessProgress[i] = guess;
wasCorrect = true;
}
}
if (wasCorrect) { if (wasCorrect) {
std::cout << "Correct!" << std::endl; std::cout << "Correct!" << std::endl;
} else { } else {
@ -219,7 +210,7 @@ int main(int argc, char *argv[]) {
std::cout << "Used letters: "; std::cout << "Used letters: ";
printContainer(guessedChars, " "); 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 // Check if all the characters in the final word have been guessed
hasWon = std::all_of(guessProgress.begin(), guessProgress.end(), hasWon = std::all_of(guessProgress.begin(), guessProgress.end(),