Compare commits

..

2 Commits

Author SHA1 Message Date
6e5fa6778f Add macro to have correct path on macOS 2024-09-11 17:44:51 +02:00
0155caa48e header 2024-09-11 17:36:05 +02:00
3 changed files with 32 additions and 24 deletions

View File

@ -1,22 +1,30 @@
// This is the .cpp file you will edit and turn in. // ____ _
// We have provided a minimal skeleton for you, // | __ ) ___ __ _ __ _| | ___ ___ _ __ _ __
// but you must finish it as described in the spec. // | _ \ / _ \ / _` |/ _` | |/ _ \ / __| '_ \| '_ \
// Also remove these comments here and add your own. // | |_) | (_) | (_| | (_| | | __/| (__| |_) | |_) |
// TODO: remove this comment header and replace it with your own // |____/ \___/ \__, |\__, |_|\___(_)___| .__/| .__/
// |___/ |___/ |_| |_|
// Author: Love Billenius <lovbi127@student.liu.se>
#include <sstream>
#include "Boggle.h" #include "Boggle.h"
#include "random.h" #include "random.h"
#include "shuffle.h" #include "shuffle.h"
#include "strlib.h" #include "strlib.h"
#include <sstream>
// The res folder isn't copied the same way on macOS
#ifdef __APPLE__
const std::string Boggle::DICTIONARY_FILE = "../../../EnglishWords.dat";
#else
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 NUM_CUBES = 16; // the number of cubes in the game
static const int CUBE_SIDES = 6; // the number of sides on each cube static const int CUBE_SIDES = 6; // the number of sides on each cube
static 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", "AAEEGN", "ABBJOO", "ACHOPS", "AFFKPS", "AOOTTW", "CIMOTU",
"AOOTTW", "CIMOTU", "DEILRX", "DELRVY", "DEILRX", "DELRVY", "DISTTY", "EEGHNW", "EEINSU", "EHRTVW",
"DISTTY", "EEGHNW", "EEINSU", "EHRTVW", "EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"};
"EIOSST", "ELRTTY", "HIMNQU", "HLNNRZ"
};
// TODO: implement the members you declared in Boggle.h // TODO: implement the members you declared in Boggle.h

View File

@ -1,21 +1,20 @@
// This is the .h file you will edit and turn in. // ____ _ _
// We have provided a minimal skeleton for you, // | __ ) ___ __ _ __ _| | ___ | |__
// but you must finish it as described in the spec. // | _ \ / _ \ / _` |/ _` | |/ _ \ | '_ \
// Also remove these comments here and add your own, as well as on the members. // | |_) | (_) | (_| | (_| | | __/_| | | |
// TODO: remove this comment header and replace it with your own // |____/ \___/ \__, |\__, |_|\___(_)_| |_|
// |___/ |___/
// Author: Love Billenius <lovbi127@student.liu.se>
#ifndef _boggle_h #ifndef _boggle_h
#define _boggle_h #define _boggle_h
#include <iostream> #include <iostream>
#include <string> #include <string>
// TODO: include any other header files you need
using namespace std;
class Boggle { class Boggle {
public: public:
const string DICTIONARY_FILE = "EnglishWords.dat"; static const std::string DICTIONARY_FILE;
const int MIN_WORD_LENGTH = 4; const int MIN_WORD_LENGTH = 4;
const int BOARD_SIZE = 4; const int BOARD_SIZE = 4;
@ -23,7 +22,8 @@ public:
private: private:
// TODO: decide the private member variables/functions and declare them // TODO: decide the private member variables/functions and declare them
}; };
#endif #endif

View File

@ -44,7 +44,7 @@ void shuffle(T** array2d, int rows, int cols) {
} }
template <typename T> template <typename T>
void shuffle(vector<T>& v) { void shuffle(std::vector<T>& v) {
for (int i = 0, length = v.size(); i < length; i++) { for (int i = 0, length = v.size(); i < length; i++) {
int j = randomInteger(i, length - 1); int j = randomInteger(i, length - 1);
if (i != j) { if (i != j) {