This commit is contained in:
Love 2024-09-05 21:31:19 +02:00
parent 703ddd90bb
commit 4d124ef849

View File

@ -151,9 +151,8 @@ int main(int argc, char *argv[]) {
}
std::vector<std::string> dictionary = readDictionary(wordLength);
std::vector<char> guessProgress(wordLength, '-');
std::cout << "So far: ";
printContainer(guessProgress);
std::string guessProgress(wordLength, '-');
std::cout << "Word: " << guessProgress << std::endl;
std::vector<char> guessedChars;
size_t wrongAttempts = 0;
@ -186,6 +185,14 @@ int main(int argc, char *argv[]) {
});
currentlyThinkingOf = biggestEntry->first;
dictionary = biggestEntry->second;
}else{
std::string &word = dictionary[0];
for (size_t i = 0; i < word.size(); i++) {
if (word[i] != guess)
continue;
currentlyThinkingOf[i] = guess;
}
}
if (showRemainingWords) {
@ -208,11 +215,12 @@ int main(int argc, char *argv[]) {
wrongAttempts++;
}
std::cout << "So far: ";
printContainer(guessProgress); // Display the current guessed word state
guessedChars.push_back(guess);
std::cout << "Used letters: ";
printContainer(guessedChars, " ");
std::cout << "Word: " << currentlyThinkingOf << std::endl;
// Check if all the characters in the final word have been guessed
hasWon = std::all_of(guessProgress.begin(), guessProgress.end(),
[](char c) { return c != '-'; });
@ -221,7 +229,7 @@ int main(int argc, char *argv[]) {
} while (!hasWon && !hasLost);
const char *out = hasWon ? "congratulations! You've won! 🎉" : "you lost.";
std::cout << "Well, the word was '" << dictionary[0] << "', " << out
std::cout << "The word was '" << dictionary[0] << "', " << out
<< std::endl;
return 0;