diff options
Diffstat (limited to 'labb5/src/Boggle.cpp')
| -rwxr-xr-x | labb5/src/Boggle.cpp | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/labb5/src/Boggle.cpp b/labb5/src/Boggle.cpp index 5bec889..7eb37e8 100755 --- a/labb5/src/Boggle.cpp +++ b/labb5/src/Boggle.cpp @@ -4,14 +4,15 @@ // Also remove these comments here and add your own. // TODO: remove this comment header and replace it with your own -#include <sstream> -#include <iostream> #include "Boggle.h" + +#include <algorithm> +#include <chrono> +#include <iostream> +#include <sstream> #include "random.h" #include "shuffle.h" #include "strlib.h" -#include <chrono> -#include <algorithm> static const int NUM_CUBES = 16; // the number of cubes in the game static const int CUBE_SIDES = 6; // the number of sides on each cube @@ -22,6 +23,12 @@ static string CUBES[NUM_CUBES] = { // the letters on all 6 sides of every cube "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ" }; +/* + * Find all immediate neighbours (including diagonally). + * + * Only returns points where x is in [0, w) and y is in [0, h). + * Additionally, points in visited are ignored. + */ vector<point> neighbours_in_range_filt(const point& p, int width, int height, const set<point>& visited) { int x, y; tie(x, y) = p; @@ -39,6 +46,17 @@ vector<point> neighbours_in_range_filt(const point& p, int width, int height, co return res; } +/* + * Return wether word starts with prefix. + */ +// There is a string::starts_with in C++20. +bool prefix_matches(const string& prefix, const string& word) { + for (int i = 0; i < prefix.length(); i++) { + if (prefix[i] != word[i]) return false; + } + return true; +} + Boggle::Boggle() { board = Grid<char>(4, 4); dictionary = Lexicon(DICTIONARY_FILE); @@ -108,13 +126,6 @@ bool Boggle::find_single_word(const string& word) const { return found; } -bool prefix_matches(const string& prefix, const string& word) { - for (int i = 0; i < prefix.length(); i++) { - if (prefix[i] != word[i]) return false; - } - return true; -} - bool Boggle::find_single_word_helper(const string& word, point cur_point, string cur_word, set<point> visited) const { if (cur_word == word && dictionary.contains(cur_word)) { return true; |
