From 94869a6f344d596fe24e304486b29ab9af4f05f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Fri, 11 Sep 2020 00:32:00 +0200 Subject: WIP E1@L2 --- labb2/evilhangman/src/evilhangman.cpp | 8 ++++++-- 1 file 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 &wordGroup, string &wordPrototype, char guess) { +bool getWordGroup(list &wordGroup, string &wordPrototype, char guess, int guesses) { map> wordGroups; // { prototype: [ match1, match2, .. ] } for (string &word: wordGroup) { if (word.find(guess) == string::npos) { @@ -61,6 +61,10 @@ bool getWordGroup(list &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 { -- cgit v1.2.1