summaryrefslogtreecommitdiffstats
path: root/labb5/src
diff options
context:
space:
mode:
Diffstat (limited to 'labb5/src')
-rwxr-xr-xlabb5/src/Boggle.cpp34
-rwxr-xr-xlabb5/src/Boggle.h1
-rwxr-xr-xlabb5/src/boggleplay.cpp9
3 files changed, 30 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;
}
diff --git a/labb5/src/Boggle.h b/labb5/src/Boggle.h
index 0082c2b..b134218 100755
--- a/labb5/src/Boggle.h
+++ b/labb5/src/Boggle.h
@@ -22,6 +22,7 @@ public:
const string DICTIONARY_FILE = "EnglishWords.dat";
const int MIN_WORD_LENGTH = 4;
static const int BOARD_SIZE = 4;
+ bool debug_mode = false;
Boggle();
bool letters_from_string(const string& letters);
diff --git a/labb5/src/boggleplay.cpp b/labb5/src/boggleplay.cpp
index b11c9d2..21b3172 100755
--- a/labb5/src/boggleplay.cpp
+++ b/labb5/src/boggleplay.cpp
@@ -41,14 +41,23 @@ void print_user_status(const Boggle& boggle) {
cout << "Your score: " << boggle.get_user_score() << endl;
}
+void ask_debug(Boggle& boggle) {
+ if (yesOrNo("Enable debug mode? ")) {
+ boggle.debug_mode = true;
+ }
+}
+
/*
* Plays one game of Boggle using the given boggle game state object.
*/
void playOneGame(Boggle& boggle) {
boggle.clear();
setup_board(boggle);
+ ask_debug(boggle);
clearConsole();
+ cout << endl; // this is later replaced by the response to the prev word
+ if (boggle.debug_mode) cout << endl; // debug mode means two lines
string user_input;
while (true) {
cout << "It's your turn!" << endl;