62 lines
1.8 KiB
C++
Executable File
62 lines
1.8 KiB
C++
Executable File
// ____ _ _
|
|
// | __ ) ___ __ _ __ _| | ___ | |__
|
|
// | _ \ / _ \ / _` |/ _` | |/ _ \ | '_ \
|
|
// | |_) | (_) | (_| | (_| | | __/_| | | |
|
|
// |____/ \___/ \__, |\__, |_|\___(_)_| |_|
|
|
// |___/ |___/
|
|
// Author: Love Billenius <lovbi127@student.liu.se>
|
|
|
|
#ifndef _boggle_h
|
|
#define _boggle_h
|
|
|
|
#include "lexicon.h"
|
|
#include <string>
|
|
#include <unordered_set>
|
|
#include <vector>
|
|
|
|
static const int g_NUM_ROLLED_CUBES = 4;
|
|
|
|
class Boggle {
|
|
public:
|
|
static const std::string s_DICTIONARY_FILE;
|
|
static const int s_MIN_WORD_LENGTH = 4;
|
|
static const int s_BOARD_SIZE = 4;
|
|
|
|
public:
|
|
Boggle();
|
|
|
|
/**
|
|
* Getter for the users played words
|
|
*/
|
|
const std::vector<std::string> &playedWords() const;
|
|
const std::array<std::string, g_NUM_ROLLED_CUBES> showingSides() const;
|
|
bool isWordEnglish(const std::string &word) const;
|
|
bool isWordLongEnough(const std::string &word) const;
|
|
bool isWordPlayed(const std::string &word) const;
|
|
static unsigned int getPointsForWord(const std::string &word);
|
|
|
|
/**
|
|
* @brief userInsert saves the users word
|
|
* @return false if the word is already inserted
|
|
*/
|
|
bool userInsert(std::string word);
|
|
/**
|
|
* @brief computerPlay calculates all possible english words which can be
|
|
* formed from the Lexicon recursivly
|
|
* @return all possible words of the current board
|
|
*/
|
|
std::vector<std::string> computerPlay() const;
|
|
|
|
private:
|
|
void backtrack(std::vector<std::string> &validWords,
|
|
std::unordered_set<string> &visited, std::string &word) const;
|
|
|
|
private:
|
|
// This is kept as a vector since there's max 16 words
|
|
std::vector<std::string> m_playedWords;
|
|
std::array<std::string, g_NUM_ROLLED_CUBES> m_showingSides;
|
|
Lexicon m_englishWords;
|
|
};
|
|
|
|
#endif
|