diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 03:25:06 +0100 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-11-29 03:25:06 +0100 |
| commit | 24fa911945b6eaa697d14afecf4d5902bc9f7071 (patch) | |
| tree | 0134164152b0befe428bc7972e15ab8e5d13be3e /labb5/src/Boggle.cpp | |
| parent | f3a2c9fbc1c946379acdd077c0d742a3298a56e3 (diff) | |
| download | tddd86-24fa911945b6eaa697d14afecf4d5902bc9f7071.tar.gz | |
debug mode
Diffstat (limited to 'labb5/src/Boggle.cpp')
| -rwxr-xr-x | labb5/src/Boggle.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/labb5/src/Boggle.cpp b/labb5/src/Boggle.cpp index 2741cae..96a77b6 100755 --- a/labb5/src/Boggle.cpp +++ b/labb5/src/Boggle.cpp @@ -83,6 +83,8 @@ void Boggle::shuffle() { bool Boggle::find_single_word(const string& word) const { auto start = std::chrono::high_resolution_clock::now(); + // We break immediately if we find a match + // Without the clock we would return right away bool found = false; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { @@ -92,15 +94,17 @@ bool Boggle::find_single_word(const string& word) const { if (found) break; } auto end = std::chrono::high_resolution_clock::now(); - if (found) { - cout << "Found word"; - } else { - cout << "Didn't find word"; - } - cout << " in " - << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()/1000.0 - << " ms" - << endl; + if (debug_mode) { + if (found) { + cout << "Found word"; + } else { + cout << "Couldn't find word"; + } + cout << " in " + << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()/1000.0 + << " ms" + << endl; + } return found; } @@ -136,11 +140,13 @@ set<string> Boggle::find_all_words() const { } } auto end = std::chrono::high_resolution_clock::now(); - cout << words.size() - << " words in " - << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()/1000.0 - << " ms" - << endl; + if (debug_mode) { + cout << words.size() + << " words in " + << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()/1000.0 + << " ms" + << endl; + } return words; } |
