simple utils

This commit is contained in:
Love 2024-09-12 14:33:29 +02:00
parent ae0512820f
commit 538a837639
2 changed files with 19 additions and 15 deletions

View File

@ -10,8 +10,8 @@
#include "random.h"
#include "shuffle.h"
#include "strlib.h"
#include <sstream>
#include <fstream>
#include <sstream>
// The res folder isn't copied the same way on macOS
#ifdef __APPLE__
@ -22,7 +22,8 @@ const std::string Boggle::DICTIONARY_FILE = "EnglishWords.dat";
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
static std::string CUBES[NUM_CUBES] = { // the letters on all 6 sides of every cube
static std::string CUBES[NUM_CUBES] =
{ // the letters on all 6 sides of every cube
"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS", "AOOTTW", "CIMOTU",
"DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
@ -41,8 +42,13 @@ std::array<std::string, NUM_ROLLED_CUBES> rollSides() {
}
Boggle::Boggle()
: showingSides(rollSides()), englishWords(Boggle::DICTIONARY_FILE) {}
bool Boggle::insertWordIfValid() {
: m_showingSides(rollSides()), m_englishWords(Boggle::DICTIONARY_FILE) {}
bool Boggle::isWordValid(const std::string &word) const {
return m_englishWords.contains(word);
}
bool Boggle::isWordPlayed(const string &word) const {
return std::find(m_playedWords.begin(), m_playedWords.end(), word) !=
m_playedWords.end();
}

View File

@ -22,14 +22,12 @@ public:
Boggle();
/**
* @return true if the word read was valid, false if not
*/
bool insertWordIfValid();
bool isWordValid(const std::string &word) const;
bool isWordPlayed(const std::string &word) const;
private:
std::vector<std::string> userWords;
std::array<std::string, 4> showingSides;
Lexicon englishWords;
std::vector<std::string> m_playedWords;
std::array<std::string, 4> m_showingSides;
Lexicon m_englishWords;
};