diff options
| -rw-r--r-- | labb2/evilhangman/src/evilhangman.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/labb2/evilhangman/src/evilhangman.cpp b/labb2/evilhangman/src/evilhangman.cpp index ce30ad5..79340c5 100644 --- a/labb2/evilhangman/src/evilhangman.cpp +++ b/labb2/evilhangman/src/evilhangman.cpp @@ -37,7 +37,7 @@ void getWordPrototype(string &wordPrototype, string &word, char guess) { * Populate `wordGroup` with the largest word group after a `guess` was made,
* given a previous word group. Returns whether the prototype has changed or not.
*/
-bool getWordGroup(list<string> &wordGroup, string &wordPrototype, char guess) {
+bool getWordGroup(list<string> &wordGroup, string &wordPrototype, char guess, int guesses) {
map<string, list<string>> wordGroups; // { prototype: [ match1, match2, .. ] }
for (string &word: wordGroup) {
if (word.find(guess) == string::npos) {
@@ -61,6 +61,10 @@ bool getWordGroup(list<string> &wordGroup, string &wordPrototype, char guess) { int maxSize = 0;
string maxPrototype;
for (auto &n : wordGroups) {
+ if (guesses == 1 && n.first == wordPrototype) {
+ wordGroup = n.second;
+ return false;
+ }
int size = n.second.size();
if (size > maxSize) {
maxSize = size;
@@ -123,7 +127,7 @@ int main() { cout << "Guess a letter: ";
char guess;
cin >> guess;
- if (getWordGroup(wordGroup, wordPrototype, guess)) {
+ if (getWordGroup(wordGroup, wordPrototype, guess, guesses)) {
// new prototype, correct guess
won = (wordPrototype.find('-') == string::npos);
} else {
|
