-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cc
60 lines (49 loc) · 1.33 KB
/
main.cc
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 <iostream>
#include <fstream>
#include <sstream>
#include <stdlib.h>
#include "boggle_board.h"
#include "word_tree.h"
#include "boggle_solver.h"
void initializeWordTree(WordTree *wordTree)
{
auto wordCount = 0;
std::fstream dictFile;
dictFile.open("dictionary.txt", std::ios::in);
if (dictFile.is_open())
{
std::string line;
while (getline(dictFile, line))
{
std::stringstream ss(line);
std::string trimmed_string;
ss >> trimmed_string;
if (wordTree->addWordToTree(&trimmed_string))
{
wordCount++;
}
}
dictFile.close(); // close the file object.
std::cout << wordCount << " words added to dictionary\n";
}
}
int main()
{
WordTree *wordTree = new WordTree();
initializeWordTree(wordTree);
BoggleBoard *myBoard = new BoggleBoard();
std::cout << BoggleBoard::SIZE << "x" << BoggleBoard::SIZE << " board" << std::endl;
std::cout << *myBoard;
BoggleSolver *solver = new BoggleSolver(myBoard, wordTree);
auto wordList = solver->solve();
auto wordItr = wordList.begin();
while (wordItr != wordList.end())
{
std::cout << *wordItr << "\n";
++wordItr;
}
delete(solver);
delete(wordTree);
delete(myBoard);
return 0;
}