From 5216d920fb26638ceda9f6391c5449c5e7bc8409 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Sun, 29 Nov 2020 01:44:00 +0100 Subject: initial work labb5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apparently I need to implement a second search function here. I don't agree with the reasoning in the lab description. > NOTERA: Programmet innehåller två rekursiva sökningar: en för att > hitta ett specifikt ord inmatat av den mänskliga spelaren och en > annan för att söka ̈över hela brädet under datorspelarens tur. Du > tänker kanske att dessa borde gå att kombinera till en integrerad > funktion, genom att göra all ordsökning i början av spelet, precis > efter att brädet initierats. För att bli godkänd på labben måste > du dock implementera människan och datorn som två separata > sökfunktioner. Det finns tillräckliga skillnader mellan de två för > att de inte ska gå att kombinera rent och snyggt. --- labb5/src/Boggle.h | 36 +++++++++++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 5 deletions(-) (limited to 'labb5/src/Boggle.h') diff --git a/labb5/src/Boggle.h b/labb5/src/Boggle.h index 3abe9b5..b6551ee 100755 --- a/labb5/src/Boggle.h +++ b/labb5/src/Boggle.h @@ -9,21 +9,47 @@ #include #include -// TODO: include any other header files you need +#include +#include "lexicon.h" +#include "grid.h" +#include using namespace std; +using point = pair; class Boggle { public: const string DICTIONARY_FILE = "EnglishWords.dat"; const int MIN_WORD_LENGTH = 4; - const int BOARD_SIZE = 4; + static const int BOARD_SIZE = 4; - // TODO: decide the public member functions and declare them + Boggle(); + bool letters_from_string(const string& letters); -private: - // TODO: decide the private member variables/functions and declare them + void read_dictionary(); + void clear(); + void shuffle(); + + void find_all_words(); + string debug_words() const; + + string board_to_string() const; + string user_words_to_string(int words_per_line = 3) const; + int get_user_words_size() const; + int get_user_score() const; + + bool word_is_valid(const string& word) const; + bool word_is_unplayed(const string& word) const; + bool add_user_word(const string& word); + +private: + void find_words_helper(point cur_point, string cur_word, set visited); + Lexicon dictionary; + Grid board; + set user_words; + set valid_words; + int user_score = 0; }; #endif -- cgit v1.2.1