User insert

This commit is contained in:
Love 2024-09-12 16:04:27 +02:00
parent 5a9bee22fe
commit f665175607
2 changed files with 16 additions and 0 deletions

View File

@ -63,6 +63,15 @@ unsigned int Boggle::getPointsForWord(const std::string &word) {
return std::min(pointsForValidWord, 0); 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<std::string> Boggle::computerPlay() const { std::vector<std::string> Boggle::computerPlay() const {
std::unordered_set<std::string> visited; std::unordered_set<std::string> visited;
std::vector<std::string> valiWords; std::vector<std::string> valiWords;

View File

@ -29,6 +29,12 @@ public:
bool isWordLongEnough(const std::string &word) const; bool isWordLongEnough(const std::string &word) const;
bool isWordPlayed(const std::string &word) const; bool isWordPlayed(const std::string &word) const;
static unsigned int getPointsForWord(const std::string &word); 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 * @brief computerPlay calculates all possible english words which can be
* formed from the Lexicon recursivly * formed from the Lexicon recursivly
@ -41,6 +47,7 @@ private:
std::unordered_set<string> &visited, std::string &word) const; std::unordered_set<string> &visited, std::string &word) const;
private: private:
// This is kept as a vector since there's max 16 words
std::vector<std::string> m_playedWords; std::vector<std::string> m_playedWords;
std::array<std::string, g_NUM_ROLLED_CUBES> m_showingSides; std::array<std::string, g_NUM_ROLLED_CUBES> m_showingSides;
Lexicon m_englishWords; Lexicon m_englishWords;