From 136451c53bcad8cf2d5cffa98f772a0ef211aca7 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Thu, 12 Sep 2024 16:04:27 +0200 Subject: [PATCH] User insert --- src/Boggle.cpp | 9 +++++++++ src/Boggle.h | 7 +++++++ 2 files changed, 16 insertions(+) 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..4c6189d 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;