blob: 8f68e923f95c6aa6074b82130e1724c7eebba6b2 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
// 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
#ifndef _boggle_h
#define _boggle_h
#include <iostream>
#include <set>
#include <string>
#include <utility>
#include "grid.h"
#include "lexicon.h"
using namespace std;
using point = pair<int, int>;
class Boggle {
public:
bool debug_mode = false;
Boggle();
/*
* Try to load a string of letters as the board.
*
* Returns wether it succeeds or not.
*/
bool board_from_string(const string& letters);
void read_dictionary();
/*
* Clear state between games.
*/
void clear();
/*
* Shuffle the board, both the dices and their locations.
*/
void shuffle();
/*
* Return whether a word can be constructed on the current board or not.
*
* Does not check if the word is a valid word or not.
* Times itself if debug_mode is enabled.
*/
bool find_single_word(const string& word) const;
/*
* Find and return all valid words that can be constructed from the current board.
*
* Times itself if debug_mode is enabled.
*/
set<string> find_all_words() const;
/*
* Convert a board to its string representation.
*
* Does not contain a trailing newline.
*/
string board_to_string() const;
/*
* Return a string represntation of all user words.
*/
string user_words_to_string(int words_per_line = 8) const;
/*
* Return a string represntation of all computer words.
*/
string computer_words_to_string(int words_per_line = 8) const;
/*
* Return a string representation of a set of words.
*/
string words_to_string(const set<string>& words, int words_per_line = 8) const;
/*
* Run calculations for when it's the computer's turn.
*
* Finds which words the computer found and how many points they're worth.
*/
void do_computer_turn();
int get_computer_words_size() const;
int get_computer_score() const;
int get_user_words_size() const;
int get_user_score() const;
bool word_is_valid(const string& word) const;
bool word_is_unplayed(const string& word) const;
/*
* Add a word the user has found and awards points.
*
* Does not perform any checks.
*/
void add_user_word(const string& word);
private:
const string DICTIONARY_FILE = "EnglishWords.dat";
const int MIN_WORD_LENGTH = 4;
static const int BOARD_SIZE = 4;
void find_all_words_helper(set<string>& words, point cur_point, string cur_word, set<point> visited) const;
bool find_single_word_helper(const string& word, point cur_point, string cur_word, set<point> visited) const;
Lexicon dictionary;
Grid<char> board;
set<string> user_words;
set<string> computer_words;
int user_score = 0;
int computer_score = 0;
};
#endif
|