simple utils
This commit is contained in:
parent
3a831b0099
commit
5eb7c59019
@ -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__
|
||||
@ -20,15 +20,16 @@ const std::string Boggle::DICTIONARY_FILE = "../../../EnglishWords.dat";
|
||||
const std::string Boggle::DICTIONARY_FILE = "EnglishWords.dat";
|
||||
#endif
|
||||
|
||||
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 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
|
||||
"AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS", "AOOTTW", "CIMOTU",
|
||||
"DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
|
||||
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
|
||||
|
||||
static const int NUM_ROLLED_CUBES = 4;
|
||||
std::array<std::string, NUM_ROLLED_CUBES> rollSides() {
|
||||
std::array<std::string, NUM_ROLLED_CUBES> rollSides() {
|
||||
// Intermediate array to shuffle
|
||||
std::array<std::string, NUM_CUBES> cubes;
|
||||
std::copy(std::begin(CUBES), std::end(CUBES), cubes.begin());
|
||||
@ -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();
|
||||
}
|
||||
|
12
src/Boggle.h
12
src/Boggle.h
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user