From ae0512820fb6d5479b5545b11c693fe1569e5dd0 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Thu, 12 Sep 2024 14:24:36 +0200 Subject: [PATCH] Roll function --- src/Boggle.cpp | 22 ++++++++++++++++++++-- src/Boggle.h | 12 ++++++++++-- src/boggleplay.cpp | 1 - 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/Boggle.cpp b/src/Boggle.cpp index bdc34b5..dffb816 100755 --- a/src/Boggle.cpp +++ b/src/Boggle.cpp @@ -11,7 +11,7 @@ #include "shuffle.h" #include "strlib.h" #include - +#include // The res folder isn't copied the same way on macOS #ifdef __APPLE__ @@ -27,4 +27,22 @@ static std::string CUBES[NUM_CUBES] = { // the letters on all 6 sides of every c "DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW", "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"}; -// TODO: implement the members you declared in Boggle.h +static const int NUM_ROLLED_CUBES = 4; +std::array rollSides() { + // Intermediate array to shuffle + std::array cubes; + std::copy(std::begin(CUBES), std::end(CUBES), cubes.begin()); + shuffle(cubes.data(), cubes.size()); + + // Just return the first NUM_ROLLED_CUBES (4pcs) entries + std::array ret; + std::copy(cubes.begin(), cubes.begin() + NUM_ROLLED_CUBES, ret.begin()); + return ret; +} + +Boggle::Boggle() + : showingSides(rollSides()), englishWords(Boggle::DICTIONARY_FILE) {} + +bool Boggle::insertWordIfValid() { + +} diff --git a/src/Boggle.h b/src/Boggle.h index 43fdb03..7909608 100755 --- a/src/Boggle.h +++ b/src/Boggle.h @@ -10,7 +10,9 @@ #define _boggle_h #include +#include #include +#include "lexicon.h" class Boggle { public: @@ -18,10 +20,16 @@ public: const int MIN_WORD_LENGTH = 4; const int BOARD_SIZE = 4; - // TODO: decide the public member functions and declare them + Boggle(); + /** + * @return true if the word read was valid, false if not + */ + bool insertWordIfValid(); private: - // TODO: decide the private member variables/functions and declare them + std::vector userWords; + std::array showingSides; + Lexicon englishWords; }; diff --git a/src/boggleplay.cpp b/src/boggleplay.cpp index 76bdcde..b3ed7ad 100755 --- a/src/boggleplay.cpp +++ b/src/boggleplay.cpp @@ -15,7 +15,6 @@ * Plays one game of Boggle using the given boggle game state object. */ void playOneGame(Boggle& boggle) { - // TODO: implement this function (and add any other functions you like to help you) }