diff --git a/src/Boggle.cpp b/src/Boggle.cpp index 25aa5e8..d6a8532 100755 --- a/src/Boggle.cpp +++ b/src/Boggle.cpp @@ -63,6 +63,15 @@ unsigned int Boggle::getPointsForWord(const std::string &word) { return std::min(pointsForValidWord, 0); } +bool Boggle::userInsert(std::string word){ + bool existsAlready = std::find(m_playedWords.begin(), m_playedWords.end(), word) != m_playedWords.end(); + if (existsAlready) + return false; + + m_playedWords.push_back(std::move(word)); + return true; +} + std::vector Boggle::computerPlay() const { std::unordered_set visited; std::vector valiWords; diff --git a/src/Boggle.h b/src/Boggle.h index 8f0e3c3..89709b4 100755 --- a/src/Boggle.h +++ b/src/Boggle.h @@ -29,6 +29,12 @@ public: bool isWordLongEnough(const std::string &word) const; bool isWordPlayed(const std::string &word) const; static unsigned int getPointsForWord(const std::string &word); + + /** + * @brief userInsert saves the users word + * @return false if the word is already inserted + */ + bool userInsert(std::string word); /** * @brief computerPlay calculates all possible english words which can be * formed from the Lexicon recursivly @@ -41,6 +47,7 @@ private: std::unordered_set &visited, std::string &word) const; private: + // This is kept as a vector since there's max 16 words std::vector m_playedWords; std::array m_showingSides; Lexicon m_englishWords;