Simplify a bit
This commit is contained in:
parent
4d124ef849
commit
dcb10a1eb7
@ -157,7 +157,6 @@ int main(int argc, char *argv[]) {
|
||||
std::vector<char> 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 {
|
||||
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(),
|
||||
|
Loading…
Reference in New Issue
Block a user