-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboggle.h
More file actions
50 lines (40 loc) · 1.61 KB
/
boggle.h
File metadata and controls
50 lines (40 loc) · 1.61 KB
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
/* Filename: boggle.h
* Author: Peter Piech
* Date Created: 07/29/2016
* Date Modified: 08/01/2016
* Description: Boggle game solver
*/
#ifndef BOGGLE_20160729_H_
#define BOGGLE_20160729_H_
#include <string>
#include <vector>
#include <unordered_set>
// Minimum length of valid words from official Boggle game rules
const static unsigned int BOGGLE_MIN_VALID_WORD_LENGTH = 3;
// Boggle class represents an instance of the game of boggle
class Boggle {
private:
// Typedefs
typedef std::unordered_set<std::string> words_set; // boggle internal set type
// Member variables
bool m_solved; // Indicates if solve method completed successfully
int m_board_h, m_board_w; // Board height & width
std::vector<std::string> m_board; // Vector entries are rows of the board
words_set m_dict, m_solns; // Dictionary & solutions sets
// Helper functions
void init(const char* board_filename, const char* dict_filename);
int index(const int row, const int col) const;
bool isValidWord(const std::string &str) const;
void solve(bool* const &visited, const int row, const int col, std::string &str);
public:
// Constructor
Boggle(const char* board_filename, const char* dict_filename);
Boggle(const std::string &board_filename, const std::string &dict_filename);
// Accessors
bool isSolved() const { return m_solved; } // Return state of the game
void print_board() const; // Output the game board
void print_solutions() const; // Output all solutions
// Modifiers
void solve(); // Analyze board & dictionary to find all solutions
};
#endif /* BOGGLE_20160729_H_ */