-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.cpp
60 lines (52 loc) · 1.63 KB
/
main.cpp
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
#include "boggle.h"
int main(int argc, char* argv[])
{
if(argc != 4)
{
cout << "Usage: ./boggle <board_file> <dictionary_file> <min_word_length>" << endl;
return 1;
}
// Default board (should be all "a")
Boggle boggle;
cout << boggle.getBoardString() << endl << endl;
// Random board
boggle.createRandomBoard();
cout << boggle.getBoardString() << endl << endl;
// Import board (if import fails, then random board will be used)
bool success = boggle.importBoard(argv[1]);
if(success)
cout << "success importing " << argv[1] << endl;
else
cout << "error importing " << argv[1] << endl;
// Import dictionary and set min word length
boggle.importDictionary(argv[2]);
stringstream ss(argv[3]);
int minWordLength = 3;
ss >> minWordLength;
boggle.setMinWordLength(minWordLength);
// Test isWord and isPrefix
string tests[] = {"a", "and", "aard", "aardvark", "aaard", "mil", "mlead", "zymurgy", "zymurg", "zymany"};
for(int i = 0; i < 10; i++)
{
bool isWord = boggle.isWord(tests[i]);
if(isWord)
cout << tests[i] << " is a word" << endl;
else
cout << tests[i] << " is NOT a word" << endl;
bool isPrefix = boggle.isPrefix(tests[i]);
if(isPrefix)
cout << tests[i] << " is a prefix" << endl;
else
cout << tests[i] << " is NOT a prefix" << endl;
}
cout << endl;
// Solve the board
cout << boggle.getBoardString() << endl << endl;
set<string> words = boggle.solveBoard();
// Print solution
cout << "Found " << words.size() << " words:" << endl;
for(set<string>::iterator it = words.begin(); it != words.end(); ++it)
{
cout << *it << endl;
}
}