summaryrefslogtreecommitdiffstats
path: root/labb5/src/Boggle.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'labb5/src/Boggle.cpp')
-rwxr-xr-xlabb5/src/Boggle.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/labb5/src/Boggle.cpp b/labb5/src/Boggle.cpp
index 9ae2d94..829be35 100755
--- a/labb5/src/Boggle.cpp
+++ b/labb5/src/Boggle.cpp
@@ -137,10 +137,11 @@ bool Boggle::find_single_word(const string& word) const {
bool found = false;
for (int y = 0; y < BOARD_SIZE; y++) {
for (int x = 0; x < BOARD_SIZE; x++) {
+ set<point> initial_points;
found = find_single_word_helper(word,
make_pair(x, y),
string(1, board[y][x]),
- set<point>());
+ initial_points);
if (found) break;
}
if (found) break;
@@ -163,9 +164,9 @@ bool Boggle::find_single_word(const string& word) const {
bool Boggle::find_single_word_helper(
const string& word,
- point cur_point,
- string cur_word,
- set<point> visited
+ const point& cur_point,
+ const string& cur_word,
+ set<point>& visited
) const {
if (cur_word == word) {
return true;
@@ -184,6 +185,7 @@ bool Boggle::find_single_word_helper(
}
}
}
+ visited.erase(cur_point);
return false;
}
@@ -192,10 +194,11 @@ set<string> Boggle::find_all_words() const {
auto start = std::chrono::high_resolution_clock::now();
for (int y = 0; y < BOARD_SIZE; y++) {
for (int x = 0; x < BOARD_SIZE; x++) {
+ set<point> initial_points;
find_all_words_helper(words,
make_pair(x, y),
string(1, board[y][x]),
- set<point>());
+ initial_points);
}
}
auto end = std::chrono::high_resolution_clock::now();
@@ -211,9 +214,9 @@ set<string> Boggle::find_all_words() const {
void Boggle::find_all_words_helper(
set<string>& words,
- point cur_point,
- string cur_word,
- set<point> visited
+ const point& cur_point,
+ const string& cur_word,
+ set<point>& visited
) const {
if (cur_word.length() >= 4
&& words.count(cur_word) == 0
@@ -233,6 +236,7 @@ void Boggle::find_all_words_helper(
find_all_words_helper(words, neighbour, new_word, visited);
}
}
+ visited.erase(cur_point);
}
string Boggle::board_to_string() const {