From 24fa911945b6eaa697d14afecf4d5902bc9f7071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 29 Nov 2020 03:25:06 +0100 Subject: debug mode --- labb5/src/Boggle.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'labb5/src/Boggle.cpp') 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(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(end - start).count()/1000.0 + << " ms" + << endl; + } return found; } @@ -136,11 +140,13 @@ set Boggle::find_all_words() const { } } auto end = std::chrono::high_resolution_clock::now(); - cout << words.size() - << " words in " - << std::chrono::duration_cast(end - start).count()/1000.0 - << " ms" - << endl; + if (debug_mode) { + cout << words.size() + << " words in " + << std::chrono::duration_cast(end - start).count()/1000.0 + << " ms" + << endl; + } return words; } -- cgit v1.2.1