Roll function

This commit is contained in:
Love 2024-09-12 14:24:36 +02:00
parent fe83e31524
commit ae0512820f
3 changed files with 30 additions and 5 deletions

View File

@ -11,7 +11,7 @@
#include "shuffle.h" #include "shuffle.h"
#include "strlib.h" #include "strlib.h"
#include <sstream> #include <sstream>
#include <fstream>
// The res folder isn't copied the same way on macOS // The res folder isn't copied the same way on macOS
#ifdef __APPLE__ #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", "DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"}; "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
// TODO: implement the members you declared in Boggle.h static const int NUM_ROLLED_CUBES = 4;
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());
shuffle(cubes.data(), cubes.size());
// Just return the first NUM_ROLLED_CUBES (4pcs) entries
std::array<std::string, NUM_ROLLED_CUBES> 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() {
}

View File

@ -10,7 +10,9 @@
#define _boggle_h #define _boggle_h
#include <iostream> #include <iostream>
#include <vector>
#include <string> #include <string>
#include "lexicon.h"
class Boggle { class Boggle {
public: public:
@ -18,10 +20,16 @@ public:
const int MIN_WORD_LENGTH = 4; const int MIN_WORD_LENGTH = 4;
const int BOARD_SIZE = 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: private:
// TODO: decide the private member variables/functions and declare them std::vector<std::string> userWords;
std::array<std::string, 4> showingSides;
Lexicon englishWords;
}; };

View File

@ -15,7 +15,6 @@
* Plays one game of Boggle using the given boggle game state object. * Plays one game of Boggle using the given boggle game state object.
*/ */
void playOneGame(Boggle& boggle) { void playOneGame(Boggle& boggle) {
// TODO: implement this function (and add any other functions you like to help you)
} }