summaryrefslogtreecommitdiffstats
path: root/labb5/src/Boggle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'labb5/src/Boggle.cpp')
-rwxr-xr-xlabb5/src/Boggle.cpp34
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;
}